|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const js = require('@eslint/js'); |
| 4 | +const globals = require('globals'); |
| 5 | + |
| 6 | +const messages = { |
| 7 | + gh237: 'See https://github.com/mochajs/mocha/issues/237', |
| 8 | + gh3604: 'See https://github.com/mochajs/mocha/issues/3604' |
| 9 | +}; |
| 10 | + |
| 11 | +module.exports = [ |
| 12 | + { |
| 13 | + ...js.configs.recommended, |
| 14 | + languageOptions: { |
| 15 | + ecmaVersion: 2018, |
| 16 | + globals: { |
| 17 | + ...globals.browser, |
| 18 | + ...globals.node |
| 19 | + }, |
| 20 | + sourceType: 'script' |
| 21 | + }, |
| 22 | + rules: { |
| 23 | + 'no-var': 'off', |
| 24 | + strict: ['error', 'global'] |
| 25 | + } |
| 26 | + }, |
| 27 | + { |
| 28 | + files: ['docs/js/**/*.js'], |
| 29 | + languageOptions: { |
| 30 | + globals: globals.browser |
| 31 | + } |
| 32 | + }, |
| 33 | + { |
| 34 | + files: [ |
| 35 | + '.eleventy.js', |
| 36 | + '.wallaby.js', |
| 37 | + 'package-scripts.js', |
| 38 | + 'karma.conf.js', |
| 39 | + 'bin/*', |
| 40 | + 'docs/_data/**/*.js', |
| 41 | + 'lib/cli/**/*.js', |
| 42 | + 'lib/nodejs/**/*.js', |
| 43 | + 'scripts/**/*.{js,mjs}', |
| 44 | + 'test/**/*.{js,mjs}', |
| 45 | + 'test/node-unit/**/*.js' |
| 46 | + ], |
| 47 | + languageOptions: { |
| 48 | + globals: globals.node, |
| 49 | + ecmaVersion: 2020, |
| 50 | + } |
| 51 | + }, |
| 52 | + { |
| 53 | + files: [ |
| 54 | + 'lib/nodejs/esm-utils.js', |
| 55 | + 'rollup.config.js', |
| 56 | + 'scripts/*.mjs', |
| 57 | + 'scripts/pick-from-package-json.js' |
| 58 | + ], |
| 59 | + languageOptions: { |
| 60 | + sourceType: 'module' |
| 61 | + } |
| 62 | + }, |
| 63 | + { |
| 64 | + files: ['test/**/*.{js,mjs}'], |
| 65 | + languageOptions: { |
| 66 | + globals: { |
| 67 | + ...globals.browser, |
| 68 | + ...globals.mocha, |
| 69 | + ...globals.node, |
| 70 | + expect: 'readonly' |
| 71 | + } |
| 72 | + } |
| 73 | + }, |
| 74 | + { |
| 75 | + files: ['test/**/*.mjs'], |
| 76 | + languageOptions: { |
| 77 | + sourceType: "module" |
| 78 | + }, |
| 79 | + }, |
| 80 | + { |
| 81 | + files: ['bin/*', 'lib/**/*.js'], |
| 82 | + rules: { |
| 83 | + 'no-restricted-globals': [ |
| 84 | + 'error', |
| 85 | + { |
| 86 | + message: messages.gh237, |
| 87 | + name: 'setTimeout' |
| 88 | + }, |
| 89 | + { |
| 90 | + message: messages.gh237, |
| 91 | + name: 'clearTimeout' |
| 92 | + }, |
| 93 | + { |
| 94 | + message: messages.gh237, |
| 95 | + name: 'setInterval' |
| 96 | + }, |
| 97 | + { |
| 98 | + message: messages.gh237, |
| 99 | + name: 'clearInterval' |
| 100 | + }, |
| 101 | + { |
| 102 | + message: messages.gh237, |
| 103 | + name: 'setImmediate' |
| 104 | + }, |
| 105 | + { |
| 106 | + message: messages.gh237, |
| 107 | + name: 'clearImmediate' |
| 108 | + }, |
| 109 | + { |
| 110 | + message: messages.gh237, |
| 111 | + name: 'Date' |
| 112 | + } |
| 113 | + ], |
| 114 | + 'no-restricted-modules': ['error', 'timers'], |
| 115 | + "no-restricted-syntax": ['error', |
| 116 | + // disallow `global.setTimeout()`, `global.setInterval()`, etc. |
| 117 | + { |
| 118 | + message: messages.gh237, |
| 119 | + selector: 'CallExpression[callee.object.name=global][callee.property.name=/(set|clear)(Timeout|Immediate|Interval)/]' |
| 120 | + }, |
| 121 | + // disallow `new global.Date()` |
| 122 | + { |
| 123 | + message: messages.gh237, |
| 124 | + selector: 'NewExpression[callee.object.name=global][callee.property.name=Date]' |
| 125 | + }, |
| 126 | + // disallow property access of `global.<timer>.*` |
| 127 | + { |
| 128 | + message: messages.gh237, |
| 129 | + selector: '*[object.object.name=global][object.property.name=/(Date|(set|clear)(Timeout|Immediate|Interval))/]:expression' |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + }, |
| 134 | + { |
| 135 | + files: ['lib/reporters/*.js'], |
| 136 | + rules: { |
| 137 | + 'no-restricted-syntax': ['error', |
| 138 | + // disallow Reporters using `console.log()` |
| 139 | + { |
| 140 | + message: messages.gh3604, |
| 141 | + selector: 'CallExpression[callee.object.name=console][callee.property.name=log]' |
| 142 | + } |
| 143 | + ] |
| 144 | + } |
| 145 | + }, |
| 146 | + { |
| 147 | + ignores: [ |
| 148 | + '**/*.{fixture,min}.{js,mjs}', |
| 149 | + 'coverage/**', |
| 150 | + 'docs/{_dist,_site,api,example}/**', |
| 151 | + 'out/**', |
| 152 | + 'test/integration/fixtures/**', |
| 153 | + ], |
| 154 | + } |
| 155 | +]; |
0 commit comments