-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
.eslintrc.cjs
112 lines (101 loc) · 2.56 KB
/
.eslintrc.cjs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* This file uses "@jsenv/eslint-config" to configure ESLint
* See https://github.com/jsenv/eslint-config#eslint-config----
*/
const {
composeEslintConfig,
eslintConfigBase,
eslintConfigForPrettier,
eslintConfigToPreferExplicitGlobals,
jsenvEslintRules,
jsenvEslintRulesForImport,
} = require("@jsenv/eslint-config");
const eslintConfig = composeEslintConfig(
eslintConfigBase,
// use "@babel/eslint-parser" until top level await is supported by ESLint default parser
// + to support import assertions in some files
{
parser: "@babel/eslint-parser",
parserOptions: {
requireConfigFile: false,
},
},
// Files in this repository are all meant to be executed in Node.js
// and we want to tell this to ESLint.
// As a result ESLint can consider `window` as undefined
// and `global` as an existing global variable.
{
env: {
node: true,
},
},
// Reuse jsenv eslint rules
{
rules: {
...jsenvEslintRules,
// Example of code changing the ESLint configuration to enable a rule:
// 'prefer-const': ['error']
},
},
// Enable import plugin
{
plugins: ["import"],
settings: {
"import/resolver": {
"@jsenv/eslint-import-resolver": {
rootDirectoryUrl: __dirname,
// logLevel: "debug",
packageConditions: ["node", "import"],
},
},
"import/extensions": [".js", ".mjs"],
},
rules: jsenvEslintRulesForImport,
},
{
plugins: ["html"],
settings: {
extensions: [".html"],
},
},
// package is "type": "module" so:
// 1. disable commonjs globals by default
// 2. Re-enable commonjs into *.cjs files
{
globals: {
__filename: "off",
__dirname: "off",
require: "off",
exports: "off",
},
overrides: [
{
files: ["**/*.cjs"],
env: {
commonjs: true,
},
// inside *.cjs files. restore commonJS "globals"
globals: {
__filename: true,
__dirname: true,
require: true,
exports: true,
},
// inside *.cjs files, use commonjs module resolution
settings: {
"import/resolver": {
"@jsenv/eslint-import-resolver": {
rootDirectoryUrl: __dirname,
packageConditions: ["node", "require"],
},
},
},
},
],
},
eslintConfigToPreferExplicitGlobals,
// We are using prettier, disable all eslint rules
// already handled by prettier.
eslintConfigForPrettier,
);
module.exports = eslintConfig;