|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const Module = require('module'); |
| 4 | +const path = require('path'); |
| 5 | + |
| 6 | +const NodePlugin = require('./tools/node_modules/eslint-plugin-node-core'); |
| 7 | +NodePlugin.RULES_DIR = path.resolve(__dirname, 'tools', 'eslint-rules'); |
| 8 | + |
| 9 | +const ModuleFindPath = Module._findPath; |
| 10 | +const hacks = [ |
| 11 | + 'eslint-plugin-node-core', |
| 12 | + 'eslint-plugin-markdown', |
| 13 | + 'babel-eslint', |
| 14 | +]; |
| 15 | +Module._findPath = (request, paths, isMain) => { |
| 16 | + const r = ModuleFindPath(request, paths, isMain); |
| 17 | + if (!r && hacks.includes(request)) { |
| 18 | + try { |
| 19 | + return require.resolve(`./tools/node_modules/${request}`); |
| 20 | + } catch (err) { |
| 21 | + return require.resolve( |
| 22 | + `./tools/node_modules/eslint/node_modules/${request}`); |
| 23 | + } |
| 24 | + } |
| 25 | + return r; |
| 26 | +}; |
| 27 | + |
| 28 | +module.exports = { |
| 29 | + root: true, |
| 30 | + plugins: ['markdown', 'node-core'], |
| 31 | + env: { node: true, es6: true }, |
| 32 | + parser: 'babel-eslint', |
| 33 | + parserOptions: { sourceType: 'script' }, |
| 34 | + overrides: [ |
| 35 | + { |
| 36 | + files: [ |
| 37 | + 'doc/api/esm.md', |
| 38 | + '*.mjs', |
| 39 | + 'test/es-module/test-esm-example-loader.js', |
| 40 | + ], |
| 41 | + parserOptions: { sourceType: 'module' }, |
| 42 | + }, |
| 43 | + ], |
| 44 | + rules: { |
| 45 | + // Possible Errors |
| 46 | + // http://eslint.org/docs/rules/#possible-errors |
| 47 | + 'for-direction': 'error', |
| 48 | + 'no-control-regex': 'error', |
| 49 | + 'no-debugger': 'error', |
| 50 | + 'no-dupe-args': 'error', |
| 51 | + 'no-dupe-keys': 'error', |
| 52 | + 'no-duplicate-case': 'error', |
| 53 | + 'no-empty-character-class': 'error', |
| 54 | + 'no-ex-assign': 'error', |
| 55 | + 'no-extra-boolean-cast': 'error', |
| 56 | + 'no-extra-parens': ['error', 'functions'], |
| 57 | + 'no-extra-semi': 'error', |
| 58 | + 'no-func-assign': 'error', |
| 59 | + 'no-invalid-regexp': 'error', |
| 60 | + 'no-irregular-whitespace': 'error', |
| 61 | + 'no-obj-calls': 'error', |
| 62 | + 'no-template-curly-in-string': 'error', |
| 63 | + 'no-unexpected-multiline': 'error', |
| 64 | + 'no-unreachable': 'error', |
| 65 | + 'no-unsafe-negation': 'error', |
| 66 | + 'use-isnan': 'error', |
| 67 | + 'valid-typeof': 'error', |
| 68 | + |
| 69 | + // Best Practices |
| 70 | + // http://eslint.org/docs/rules/#best-practices |
| 71 | + 'accessor-pairs': 'error', |
| 72 | + 'array-callback-return': 'error', |
| 73 | + 'dot-location': ['error', 'property'], |
| 74 | + eqeqeq: ['error', 'smart'], |
| 75 | + 'no-fallthrough': 'error', |
| 76 | + 'no-global-assign': 'error', |
| 77 | + 'no-multi-spaces': ['error', { ignoreEOLComments: true }], |
| 78 | + 'no-octal': 'error', |
| 79 | + 'no-proto': 'error', |
| 80 | + 'no-redeclare': 'error', |
| 81 | + 'no-restricted-properties': [ |
| 82 | + 'error', |
| 83 | + { |
| 84 | + object: 'assert', |
| 85 | + property: 'deepEqual', |
| 86 | + message: 'Use assert.deepStrictEqual().', |
| 87 | + }, |
| 88 | + { |
| 89 | + object: 'assert', |
| 90 | + property: 'notDeepEqual', |
| 91 | + message: 'Use assert.notDeepStrictEqual().', |
| 92 | + }, |
| 93 | + { |
| 94 | + object: 'assert', |
| 95 | + property: 'equal', |
| 96 | + message: 'Use assert.astrictEqual() rather than assert.equal().', |
| 97 | + }, |
| 98 | + { |
| 99 | + object: 'assert', |
| 100 | + property: 'notEqual', |
| 101 | + message: 'Use assert.notStrictEqual() rather than assert.notEqual().', |
| 102 | + }, |
| 103 | + { |
| 104 | + property: '__defineGetter__', |
| 105 | + message: '__defineGetter__ is deprecated.', |
| 106 | + }, |
| 107 | + { |
| 108 | + property: '__defineSetter__', |
| 109 | + message: '__defineSetter__ is deprecated.', |
| 110 | + } |
| 111 | + ], |
| 112 | + 'no-return-await': 'error', |
| 113 | + 'no-self-assign': 'error', |
| 114 | + 'no-throw-literal': 'error', |
| 115 | + 'no-unused-labels': 'error', |
| 116 | + 'no-useless-call': 'error', |
| 117 | + 'no-useless-concat': 'error', |
| 118 | + 'no-useless-escape': 'error', |
| 119 | + 'no-useless-return': 'error', |
| 120 | + 'no-void': 'error', |
| 121 | + 'no-with': 'error', |
| 122 | + |
| 123 | + // Strict Mode |
| 124 | + // http://eslint.org/docs/rules/#strict-mode |
| 125 | + strict: ['error', 'global'], |
| 126 | + |
| 127 | + // Variables |
| 128 | + // http://eslint.org/docs/rules/#variables |
| 129 | + 'no-delete-var': 'error', |
| 130 | + 'no-undef': 'error', |
| 131 | + 'no-unused-vars': ['error', { args: 'none' }], |
| 132 | + 'no-use-before-define': ['error', { |
| 133 | + classes: true, |
| 134 | + functions: false, |
| 135 | + variables: false, |
| 136 | + }], |
| 137 | + |
| 138 | + // Node.js and CommonJS |
| 139 | + // http://eslint.org/docs/rules/#nodejs-and-commonjs |
| 140 | + 'no-mixed-requires': 'error', |
| 141 | + 'no-new-require': 'error', |
| 142 | + 'no-path-concat': 'error', |
| 143 | + 'no-restricted-modules': ['error', 'sys'], |
| 144 | + |
| 145 | + // Stylistic Issues |
| 146 | + // http://eslint.org/docs/rules/#stylistic-issues' |
| 147 | + 'block-spacing': 'error', |
| 148 | + 'brace-style': ['error', '1tbs', { allowSingleLine: true }], |
| 149 | + 'comma-dangle': ['error', 'only-multiline'], |
| 150 | + 'comma-spacing': 'error', |
| 151 | + 'comma-style': 'error', |
| 152 | + 'computed-property-spacing': 'error', |
| 153 | + 'eol-last': 'error', |
| 154 | + 'func-call-spacing': 'error', |
| 155 | + 'func-name-matching': 'error', |
| 156 | + 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], |
| 157 | + indent: ['error', 2, { |
| 158 | + ArrayExpression: 'first', |
| 159 | + CallExpression: { arguments: 'first' }, |
| 160 | + FunctionDeclaration: { parameters: 'first' }, |
| 161 | + FunctionExpression: { parameters: 'first' }, |
| 162 | + MemberExpression: 'off', |
| 163 | + ObjectExpression: 'first', |
| 164 | + SwitchCase: 1, |
| 165 | + }], |
| 166 | + 'key-spacing': ['error', { mode: 'minimum' }], |
| 167 | + 'keyword-spacing': 'error', |
| 168 | + 'linebreak-style': ['error', 'unix'], |
| 169 | + 'max-len': ['error', { |
| 170 | + code: 80, |
| 171 | + ignorePattern: '^// Flags:', |
| 172 | + ignoreRegExpLiterals: true, |
| 173 | + ignoreUrls: true, |
| 174 | + tabWidth: 2, |
| 175 | + }], |
| 176 | + 'new-parens': 'error', |
| 177 | + 'no-lonely-if': 'error', |
| 178 | + 'no-mixed-spaces-and-tabs': 'error', |
| 179 | + 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }], |
| 180 | + /* eslint-disable max-len, quotes */ |
| 181 | + 'no-restricted-syntax': [ |
| 182 | + 'error', |
| 183 | + { |
| 184 | + selector: `CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])`, |
| 185 | + message: 'use a regular expression for second argument of assert.throws()', |
| 186 | + }, |
| 187 | + { |
| 188 | + selector: `CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]`, |
| 189 | + message: 'assert.throws() must be invoked with at least two arguments.', |
| 190 | + }, |
| 191 | + { |
| 192 | + selector: `CallExpression[callee.name='setTimeout'][arguments.length<2]`, |
| 193 | + message: 'setTimeout() must be invoked with at least two arguments.', |
| 194 | + }, |
| 195 | + { |
| 196 | + selector: `CallExpression[callee.name='setInterval'][arguments.length<2]`, |
| 197 | + message: 'setInterval() must be invoked with at least 2 arguments.', |
| 198 | + }, |
| 199 | + { |
| 200 | + selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]', |
| 201 | + message: 'Use new keyword when throwing an Error.', |
| 202 | + } |
| 203 | + ], |
| 204 | + /* eslint-enable max-len, quotes */ |
| 205 | + 'no-tabs': 'error', |
| 206 | + 'no-trailing-spaces': 'error', |
| 207 | + 'object-curly-spacing': ['error', 'always'], |
| 208 | + 'one-var-declaration-per-line': 'error', |
| 209 | + 'operator-linebreak': ['error', 'after'], |
| 210 | + quotes: ['error', 'single', 'avoid-escape'], |
| 211 | + semi: 'error', |
| 212 | + 'semi-spacing': 'error', |
| 213 | + 'space-before-blocks': ['error', 'always'], |
| 214 | + 'space-before-function-paren': ['error', { |
| 215 | + anonymous: 'never', |
| 216 | + named: 'never', |
| 217 | + asyncArrow: 'always', |
| 218 | + }], |
| 219 | + 'space-in-parens': ['error', 'never'], |
| 220 | + 'space-infix-ops': 'error', |
| 221 | + 'space-unary-ops': 'error', |
| 222 | + 'unicode-bom': 'error', |
| 223 | + |
| 224 | + // ECMAScript 6 |
| 225 | + // http://eslint.org/docs/rules/#ecmascript-6 |
| 226 | + 'arrow-parens': ['error', 'always'], |
| 227 | + 'arrow-spacing': ['error', { before: true, after: true }], |
| 228 | + 'constructor-super': 'error', |
| 229 | + 'no-class-assign': 'error', |
| 230 | + 'no-confusing-arrow': 'error', |
| 231 | + 'no-const-assign': 'error', |
| 232 | + 'no-dupe-class-members': 'error', |
| 233 | + 'no-new-symbol': 'error', |
| 234 | + 'no-this-before-super': 'error', |
| 235 | + 'prefer-const': ['error', { ignoreReadBeforeAssign: true }], |
| 236 | + 'rest-spread-spacing': 'error', |
| 237 | + 'symbol-description': 'error', |
| 238 | + 'template-curly-spacing': 'error', |
| 239 | + |
| 240 | + // Custom rules in from eslint-plugin-node-core |
| 241 | + 'node-core/no-unescaped-regexp-dot': 'error', |
| 242 | + }, |
| 243 | + globals: { |
| 244 | + COUNTER_HTTP_CLIENT_REQUEST: false, |
| 245 | + COUNTER_HTTP_CLIENT_RESPONSE: false, |
| 246 | + COUNTER_HTTP_SERVER_REQUEST: false, |
| 247 | + COUNTER_HTTP_SERVER_RESPONSE: false, |
| 248 | + COUNTER_NET_SERVER_CONNECTION: false, |
| 249 | + COUNTER_NET_SERVER_CONNECTION_CLOSE: false, |
| 250 | + DTRACE_HTTP_CLIENT_REQUEST: false, |
| 251 | + DTRACE_HTTP_CLIENT_RESPONSE: false, |
| 252 | + DTRACE_HTTP_SERVER_REQUEST: false, |
| 253 | + DTRACE_HTTP_SERVER_RESPONSE: false, |
| 254 | + DTRACE_NET_SERVER_CONNECTION: false, |
| 255 | + DTRACE_NET_STREAM_END: false, |
| 256 | + LTTNG_HTTP_CLIENT_REQUEST: false, |
| 257 | + LTTNG_HTTP_CLIENT_RESPONSE: false, |
| 258 | + LTTNG_HTTP_SERVER_REQUEST: false, |
| 259 | + LTTNG_HTTP_SERVER_RESPONSE: false, |
| 260 | + LTTNG_NET_SERVER_CONNECTION: false, |
| 261 | + LTTNG_NET_STREAM_END: false, |
| 262 | + internalBinding: false, |
| 263 | + }, |
| 264 | +}; |
0 commit comments