@servicenow/eslint-plugin-sdk-app-plugin 2.2.9 → 3.0.0

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.
@@ -9,7 +9,6 @@ module.exports = {
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
- 'no-console': 'error',
13
12
  '@servicenow/sdk-app-plugin/no-unsupported-node-builtins': 'error'
14
13
  }
15
14
  }
@@ -1,7 +1,7 @@
1
1
  const globals = require('globals')
2
2
  const { READ } = require('@eslint-community/eslint-utils')
3
3
 
4
- const globalsAllowList = []
4
+ const globalsAllowList = ['console', 'fetch']
5
5
  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
 
@@ -18,12 +18,12 @@ const getRestrictedGlobals = () => {
18
18
  return globalRules.concat(browserRules)
19
19
  }
20
20
 
21
- const getCoreNodeModules = () => ["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 = ["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"]
22
22
 
23
- const getNodeGlobals = () => Object.keys(globals.nodeBuiltin)
23
+ const getNodeGlobals = () => Object.keys(globals.nodeBuiltin).filter((key) => !globalsAllowList.includes(key))
24
24
 
25
25
  const createTrackMap = (isNodeGlobals) => {
26
- const trackMapItems = isNodeGlobals ? getNodeGlobals() : getCoreNodeModules()
26
+ const trackMapItems = isNodeGlobals ? getNodeGlobals() : coreNodeModules
27
27
  const trackMap = {}
28
28
 
29
29
  for(const item of trackMapItems) {
@@ -40,6 +40,6 @@ const createTrackMap = (isNodeGlobals) => {
40
40
  module.exports = {
41
41
  getRestrictedGlobals,
42
42
  createTrackMap,
43
- getCoreNodeModules,
43
+ coreNodeModules,
44
44
  getNodeGlobals
45
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicenow/eslint-plugin-sdk-app-plugin",
3
- "version": "2.2.9",
3
+ "version": "3.0.0",
4
4
  "description": "Plugin to disallow Browser and Node.js APIs not supported in rhino engine",
5
5
  "keywords": [
6
6
  "eslint",
@@ -1,6 +1,6 @@
1
1
  const { RuleTester } = require('eslint');
2
2
  const noUnsupportedNodeBuiltins = require('../../lib/rules/no-unsupported-node-builtins');
3
- const { getCoreNodeModules, getNodeGlobals } = require('../../lib/util/utility');
3
+ const { coreNodeModules, getNodeGlobals } = require('../../lib/util/utility');
4
4
 
5
5
  const ruleTester = new RuleTester({
6
6
  parserOptions: { sourceType: 'module' },
@@ -9,17 +9,16 @@ const ruleTester = new RuleTester({
9
9
 
10
10
  const getInvalidsForNoUnsupportedNodeBuiltsRule = () => {
11
11
  const invalids = []
12
- const nodeModules = getCoreNodeModules()
13
12
  const nodeGlobals = getNodeGlobals()
14
13
 
15
- for(const module of nodeModules) {
14
+ for(const module of coreNodeModules) {
16
15
  invalids.push({
17
16
  code: `const ${module} = require('${module}')`,
18
17
  errors: [{ message: `The ${module} Node.js API is not supported in now platform.` }]
19
18
  })
20
19
  }
21
20
 
22
- for(const module of nodeModules) {
21
+ for(const module of coreNodeModules) {
23
22
  invalids.push({
24
23
  code: `import ${module} from '${module}'`,
25
24
  errors: [{ message: `The ${module} Node.js API is not supported in now platform.` }]
@@ -46,6 +45,14 @@ ruleTester.run(
46
45
  code: "const fs = {readFileSync: function(){}}; fs.readFileSync()"
47
46
  },{
48
47
  code: "const Buffer = {from: function(){}}; Buffer.from()"
48
+ },{
49
+ code: `const validFunction = () => {
50
+ fetch("https://api.example.com/data")
51
+ .then(response => response.json())
52
+ .then(data => console.log(data))
53
+ .catch(error => console.error('Error:', error));
54
+ };
55
+ validFunction();`
49
56
  }],
50
57
  invalid: getInvalidsForNoUnsupportedNodeBuiltsRule()
51
58
  }