eslint-plugin-servicenow v2.0.0
eslint-plugin-servicenow
This plugin contains rules that help enforce ServiceNow best practices. It also guards against using unsupported JavaScript features, such as Promises, async/await, and BigInt (see: JavaScript engine feature support).
Installation
You'll first need to install ESLint:
npm i eslint --save-devNext, install eslint-plugin-servicenow:
npm install eslint-plugin-servicenow --save-devNote: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-servicenow globally.
Usage
Add servicenow to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": [
"servicenow"
]
}Using the Recommended Configuration
To enable the recommended rules, extend your .eslintrc:
{
"extends": ["plugin:servicenow/recommended"]
}Manual Setup
Specify individual rules under the rules section:
{
"rules": {
"servicenow/no-hardcoded-sysids": "warn",
"servicenow/no-at-method": "warn",
"servicenow/no-promise": "warn",
"servicenow/no-weak-references": "warn",
...
}
}List of Rules
servicenow/no-hardcoded-sysids
Warns against hardcoded sys_ids.
Invalid
var id = "0329a956a9bb0000b0a7619be1050e41";Valid
var id = getSysID();servicenow/no-at-method
Warns against using the .at() method as it's not fully supported by ServiceNow.
Invalid
arr.at(1);
typedArr.at(1);
'hello'.at(1);Valid
'hello'.charAt(1);
arr[1];
arr.slice(1,2);servicenow/no-promise
Warns against using Promises.
Invalid
new Promise((resolve, reject) => {});servicenow/no-weak-references
Warns against weak references.
Invalid
new WeakMap();Valid
new Map();servicenow/no-async-await
Warns against using async/await syntax.
Invalid
async function myFunc() {
await someFunction();
}servicenow/no-async-iterators
Warns against using async iterators.
****#### Invalid:
for await (let item of asyncIterable) {}Valid
for (let item of iterable) {}servicenow/no-bigint-and-dataview
Warns against using BigInt.
Invalid
const bigInt = 123n;Valid
const number = 123;servicenow/no-date-tojson
Warns against using Date.prototype.toJSON().
Invalid
const date = new Date();
const jsonDate = date.toJSON();Valid
const date = new Date();
const stringDate = date.toString();servicenow/no-packages-calls
Disallows certain package calls.
Invalid
const result = Packages.com.glide.Glide.someMethod();Valid
const result = Glide.someMethod();servicenow/no-private-class-methods
Disallows the use of private class methods.
Invalid
class MyClass {
#myPrivateMethod() {}
}Valid
class MyClass {
myPublicMethod() {}
}servicenow/no-proxy-internal-calls
Warns against internal proxy calls.
Invalid
const p = new Proxy(target, handler);Valid
const obj = { prop: value };servicenow/no-regexp-lookbehind
Warns against using RegExp lookbehind assertions.
Invalid
const regex = /(?<=@)\\w+/;Valid
const regex = /@\\w+/;servicenow/no-setprototypeof
Disallows the use of Object.setPrototypeOf.
Invalid
Object.setPrototypeOf(obj, prototype);Valid
const newObj = Object.create(prototype);servicenow/no-shared-memory-atomics
Disallows the use of shared memory and atomics.
Invalid
Atomics.add(sharedArray, index, value);Valid
array[index] = value;servicenow/no-typed-arrays
Disallows the use of Typed Arrays and DataView methods for typed arrays.
Invalid
const int8 = new Int8Array();
const data = new DataView(buffer);
data.getInt8(0);Valid
const regularArray = [1, 2, 3];
const obj = { byte: 8 };