-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
.eslintrc.local.js
37 lines (34 loc) · 1.3 KB
/
.eslintrc.local.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { resolve, relative } = require('path')
// Create an override to lockdown a file to es6 syntax only
// and only allow it to require an allowlist of files
const rel = (p) => relative(__dirname, resolve(__dirname, p))
const braces = (a) => a.length > 1 ? `{${a.map(rel).join(',')}}` : a[0]
const es6Files = (e) => Object.entries(e).map(([file, allow]) => ({
files: `./${rel(file)}`,
parserOptions: {
ecmaVersion: 6,
},
rules: Array.isArray(allow) ? {
'node/no-restricted-require': ['error', [{
name: ['/**', `!${__dirname}/${braces(allow)}`],
message: `This file can only require: ${allow.join(',')}`,
}]],
} : {},
}))
module.exports = {
rules: {
'no-console': 'error',
},
overrides: es6Files({
'index.js': ['lib/cli.js'],
'bin/npm-cli.js': ['lib/cli.js'],
'lib/cli.js': ['lib/cli/validate-engines.js'],
'lib/cli/validate-engines.js': ['package.json'],
// TODO: This file should also have its requires restricted as well since it
// is an entry point but it currently pulls in config definitions which have
// a large require graph, so that is not currently feasible. A future config
// refactor should keep that in mind and see if only config definitions can
// be exported in a way that is compatible with ES6.
'bin/npx-cli.js': null,
}),
}