eslint-plugin-servicenow

2.0.0 • Public • Published

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-dev

Next, install eslint-plugin-servicenow:

npm install eslint-plugin-servicenow --save-dev

Note: 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"
    ]
}

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 };

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    8
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.0
    8
  • 0.1.0
    0

Package Sidebar

Install

npm i eslint-plugin-servicenow

Weekly Downloads

8

Version

2.0.0

License

MIT

Unpacked Size

28.3 kB

Total Files

39

Last publish

Collaborators

  • arnoudkooi