@servicenow/eslint-plugin-sdk-app-plugin 3.0.3 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js CHANGED
@@ -1,16 +1,10 @@
1
- 'use strict';
2
-
3
1
  module.exports = {
4
- parserOptions: {
5
- ecmaVersion: 'latest',
6
- },
7
- root: true,
8
- extends: [
9
- 'eslint:recommended',
10
- 'plugin:eslint-plugin/recommended',
11
- 'plugin:n/recommended',
12
- ],
13
- env: {
14
- node: true,
15
- }
16
- };
2
+ parserOptions: {
3
+ ecmaVersion: 'latest',
4
+ },
5
+ root: true,
6
+ extends: ['eslint:recommended', 'plugin:eslint-plugin/recommended', 'plugin:n/recommended'],
7
+ env: {
8
+ node: true,
9
+ },
10
+ }
@@ -2,13 +2,13 @@ const { getRestrictedGlobals } = require('../util/utility')
2
2
  const restrictedGlobals = getRestrictedGlobals()
3
3
 
4
4
  module.exports = {
5
- plugins:['@servicenow/sdk-app-plugin'],
6
- rules:{
7
- '@servicenow/sdk-app-plugin/file-extension-in-import':['error','always'],
8
- 'no-restricted-globals':['error',...restrictedGlobals],
5
+ plugins: ['@servicenow/sdk-app-plugin'],
6
+ rules: {
7
+ '@servicenow/sdk-app-plugin/file-extension-in-import': ['error', 'always'],
8
+ 'no-restricted-globals': ['error', ...restrictedGlobals],
9
9
  '@servicenow/sdk-app-plugin/no-dynamic-import': 'error',
10
10
  '@servicenow/sdk-app-plugin/no-regexp-lookbehind-assertions': 'error',
11
11
  '@servicenow/sdk-app-plugin/no-regexp-unicode-property-escapes': 'error',
12
- '@servicenow/sdk-app-plugin/no-unsupported-node-builtins': 'error'
13
- }
14
- }
12
+ '@servicenow/sdk-app-plugin/no-unsupported-node-builtins': 'error',
13
+ },
14
+ }
package/lib/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  module.exports = {
2
- configs:{
3
- 'recommended':require('./configs/recommended')
2
+ configs: {
3
+ recommended: require('./configs/recommended'),
4
4
  },
5
- rules:{
6
- 'file-extension-in-import':require('eslint-plugin-n/lib/rules/file-extension-in-import'),
7
- 'no-async-functions':require('eslint-plugin-es-x/lib/rules/no-async-functions'),
8
- 'no-promise':require('./rules/no-promise'),
5
+ rules: {
6
+ 'file-extension-in-import': require('eslint-plugin-n/lib/rules/file-extension-in-import'),
7
+ 'no-async-functions': require('eslint-plugin-es-x/lib/rules/no-async-functions'),
8
+ 'no-promise': require('./rules/no-promise'),
9
9
  'no-dynamic-import': require('eslint-plugin-es-x/lib/rules/no-dynamic-import'),
10
10
  'no-regexp-lookbehind-assertions': require('eslint-plugin-es-x/lib/rules/no-regexp-lookbehind-assertions'),
11
11
  'no-regexp-unicode-property-escapes': require('eslint-plugin-es-x/lib/rules/no-regexp-unicode-property-escapes'),
12
- 'no-unsupported-node-builtins': require('./rules/no-unsupported-node-builtins')
13
- }
14
- }
12
+ 'no-unsupported-node-builtins': require('./rules/no-unsupported-node-builtins'),
13
+ },
14
+ }
@@ -13,31 +13,33 @@ module.exports = {
13
13
  docs: {
14
14
  description: 'disallow the `Promise` class.',
15
15
  category: 'ES2015',
16
- recommended: false
16
+ recommended: false,
17
17
  },
18
18
  fixable: null,
19
19
  messages: {
20
- forbidden: 'ES2015 Promise class is not supported in now platform.'
20
+ forbidden: 'ES2015 Promise class is not supported in now platform.',
21
21
  },
22
- schema:[],
23
- type:'problem',
22
+ schema: [],
23
+ type: 'problem',
24
24
  },
25
25
  create(context) {
26
26
  return {
27
27
  CallExpression(node) {
28
- if(node.callee.type === 'MemberExpression' &&
28
+ if (
29
+ node.callee.type === 'MemberExpression' &&
29
30
  node.callee.object.name === 'Promise' &&
30
31
  node.callee.object.type === 'Identifier' &&
31
- PROMISE_STATIC_METHODS[node.callee.property.name]) {
32
- context.report({context,node, messageId:'forbidden'})
32
+ PROMISE_STATIC_METHODS[node.callee.property.name]
33
+ ) {
34
+ context.report({ context, node, messageId: 'forbidden' })
33
35
  }
34
36
  },
35
37
 
36
38
  NewExpression(node) {
37
- if(node.callee.name === 'Promise') {
38
- context.report({context,node, messageId:'forbidden'})
39
+ if (node.callee.name === 'Promise') {
40
+ context.report({ context, node, messageId: 'forbidden' })
39
41
  }
40
- }
42
+ },
41
43
  }
42
- }
43
- }
44
+ },
45
+ }
@@ -6,7 +6,7 @@ const BROWSER_API_WARNING = 'Web APIs are not supported by the now platform'
6
6
  const NO_GLOBAL_THIS = 'ES2020 `globalThis` variable is not supported by the now platform'
7
7
 
8
8
  const getRestrictedGlobals = () => {
9
- const globalRules = [{name:'globalThis', message: NO_GLOBAL_THIS}]
9
+ const globalRules = [{ name: 'globalThis', message: NO_GLOBAL_THIS }]
10
10
  const browserRules = Object.keys(globals.browser)
11
11
  .filter((key) => !globalsAllowList.includes(key))
12
12
  .map((key) => {
@@ -18,19 +18,53 @@ const getRestrictedGlobals = () => {
18
18
  return globalRules.concat(browserRules)
19
19
  }
20
20
 
21
- const coreNodeModules = ["assert","buffer","child_process","cluster","crypto","dgram","dns","domain","events","freelist","fs","http","https","module","net","os","path","punycode","querystring","readline","repl","smalloc","stream","string_decoder","sys","timers","tls","tracing","tty","url","util","vm","zlib"]
21
+ const coreNodeModules = [
22
+ 'assert',
23
+ 'buffer',
24
+ 'child_process',
25
+ 'cluster',
26
+ 'crypto',
27
+ 'dgram',
28
+ 'dns',
29
+ 'domain',
30
+ 'events',
31
+ 'freelist',
32
+ 'fs',
33
+ 'http',
34
+ 'https',
35
+ 'module',
36
+ 'net',
37
+ 'os',
38
+ 'path',
39
+ 'punycode',
40
+ 'querystring',
41
+ 'readline',
42
+ 'repl',
43
+ 'smalloc',
44
+ 'stream',
45
+ 'string_decoder',
46
+ 'sys',
47
+ 'timers',
48
+ 'tls',
49
+ 'tracing',
50
+ 'tty',
51
+ 'url',
52
+ 'util',
53
+ 'vm',
54
+ 'zlib',
55
+ ]
22
56
 
23
57
  const getNodeGlobals = () => Object.keys(globals.nodeBuiltin).filter((key) => !globalsAllowList.includes(key))
24
58
 
25
59
  const createTrackMap = (isNodeGlobals) => {
26
60
  const trackMapItems = isNodeGlobals ? getNodeGlobals() : coreNodeModules
27
61
  const trackMap = {}
28
-
29
- for(const item of trackMapItems) {
62
+
63
+ for (const item of trackMapItems) {
30
64
  trackMap[item] = {
31
- [READ] : {
32
- name: item
33
- }
65
+ [READ]: {
66
+ name: item,
67
+ },
34
68
  }
35
69
  }
36
70
 
@@ -41,5 +75,5 @@ module.exports = {
41
75
  getRestrictedGlobals,
42
76
  createTrackMap,
43
77
  coreNodeModules,
44
- getNodeGlobals
45
- }
78
+ getNodeGlobals,
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicenow/eslint-plugin-sdk-app-plugin",
3
- "version": "3.0.3",
3
+ "version": "4.0.1",
4
4
  "description": "Plugin to disallow Browser and Node.js APIs not supported in rhino engine",
5
5
  "keywords": [
6
6
  "eslint",
@@ -26,12 +26,10 @@
26
26
  },
27
27
  "license": "MIT",
28
28
  "engines": {
29
- "node": ">=18.16.1",
30
- "pnpm": ">=9.4.0"
29
+ "node": ">=20.18.0",
30
+ "pnpm": ">=10.8.0"
31
31
  },
32
32
  "scripts": {
33
- "lint": "npm-run-all \"lint:*\"",
34
- "lint:js": "eslint .",
35
33
  "test": "mocha tests --recursive"
36
34
  }
37
35
  }
@@ -1,26 +1,26 @@
1
- const { RuleTester } = require('eslint');
2
- const noPromise = require('../../lib/rules/no-promise');
1
+ const { RuleTester } = require('eslint')
2
+ const noPromise = require('../../lib/rules/no-promise')
3
3
 
4
4
  const ruleTester = new RuleTester({
5
- parserOptions: { ecmaVersion: 2015 }
6
- });
5
+ parserOptions: { ecmaVersion: 2015 },
6
+ })
7
7
 
8
8
  const errorMessages = [{ message: 'ES2015 Promise class is not supported in now platform.' }]
9
9
 
10
- ruleTester.run(
11
- 'no-promise',
12
- noPromise,
13
- {
14
- valid: [{
10
+ ruleTester.run('no-promise', noPromise, {
11
+ valid: [
12
+ {
15
13
  code: "const Promise = 'value';",
16
- }],
17
- invalid: [{
14
+ },
15
+ ],
16
+ invalid: [
17
+ {
18
18
  code: 'const p = new Promise()',
19
19
  errors: errorMessages,
20
20
  },
21
21
  {
22
22
  code: 'Promise.all()',
23
- errors: errorMessages
24
- }],
25
- }
26
- );
23
+ errors: errorMessages,
24
+ },
25
+ ],
26
+ })
@@ -1,59 +1,60 @@
1
- const { RuleTester } = require('eslint');
2
- const noUnsupportedNodeBuiltins = require('../../lib/rules/no-unsupported-node-builtins');
3
- const { coreNodeModules, getNodeGlobals } = require('../../lib/util/utility');
1
+ const { RuleTester } = require('eslint')
2
+ const noUnsupportedNodeBuiltins = require('../../lib/rules/no-unsupported-node-builtins')
3
+ const { coreNodeModules, getNodeGlobals } = require('../../lib/util/utility')
4
4
 
5
5
  const ruleTester = new RuleTester({
6
6
  parserOptions: { sourceType: 'module' },
7
- env: {node: true, es6: true}
8
- });
7
+ env: { node: true, es6: true },
8
+ })
9
9
 
10
10
  const getInvalidsForNoUnsupportedNodeBuiltsRule = () => {
11
11
  const invalids = []
12
12
  const nodeGlobals = getNodeGlobals()
13
13
 
14
- for(const module of coreNodeModules) {
14
+ for (const module of coreNodeModules) {
15
15
  invalids.push({
16
16
  code: `const ${module} = require('${module}')`,
17
- errors: [{ message: `The ${module} Node.js API is not supported in now platform.` }]
17
+ errors: [{ message: `The ${module} Node.js API is not supported in now platform.` }],
18
18
  })
19
19
  }
20
20
 
21
- for(const module of coreNodeModules) {
21
+ for (const module of coreNodeModules) {
22
22
  invalids.push({
23
23
  code: `import ${module} from '${module}'`,
24
- errors: [{ message: `The ${module} Node.js API is not supported in now platform.` }]
24
+ errors: [{ message: `The ${module} Node.js API is not supported in now platform.` }],
25
25
  })
26
26
  }
27
27
 
28
- for(const global of nodeGlobals) {
28
+ for (const global of nodeGlobals) {
29
29
  invalids.push({
30
30
  code: `const x = ${global}`,
31
- errors: [{ message: `The ${global} Node.js API is not supported in now platform.` }]
31
+ errors: [{ message: `The ${global} Node.js API is not supported in now platform.` }],
32
32
  })
33
33
  }
34
34
 
35
35
  return invalids
36
36
  }
37
37
 
38
- ruleTester.run(
39
- 'no-unsupported-node-builtins',
40
- noUnsupportedNodeBuiltins,
41
- {
42
- valid: [{
38
+ ruleTester.run('no-unsupported-node-builtins', noUnsupportedNodeBuiltins, {
39
+ valid: [
40
+ {
43
41
  code: "const fs = {'Dir':'cool'}; const x = fs.Dir",
44
- },{
45
- code: "const fs = {readFileSync: function(){}}; fs.readFileSync()"
46
- },{
47
- code: "const Buffer = {from: function(){}}; Buffer.from()"
48
- },{
42
+ },
43
+ {
44
+ code: 'const fs = {readFileSync: function(){}}; fs.readFileSync()',
45
+ },
46
+ {
47
+ code: 'const Buffer = {from: function(){}}; Buffer.from()',
48
+ },
49
+ {
49
50
  code: `const validFunction = () => {
50
51
  fetch("https://api.example.com/data")
51
52
  .then(response => response.json())
52
53
  .then(data => console.log(data))
53
54
  .catch(error => console.error('Error:', error));
54
55
  };
55
- validFunction();`
56
- }],
57
- invalid: getInvalidsForNoUnsupportedNodeBuiltsRule()
58
- }
59
- );
56
+ validFunction();`,
57
+ },
58
+ ],
59
+ invalid: getInvalidsForNoUnsupportedNodeBuiltsRule(),
60
+ })