Skip to content

Commit

Permalink
feat(linter): allow env and globals in overrides configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Feb 8, 2025
1 parent 7b10cad commit 4c309f2
Show file tree
Hide file tree
Showing 17 changed files with 615 additions and 51 deletions.
34 changes: 29 additions & 5 deletions apps/oxlint/fixtures/overrides/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
{
"globals": {
"DefaultFoo": "readonly"
},
"rules": {
"no-var": "error",
"no-console": "error"
"no-console": "error",
"no-global-assign": "error"
},
"overrides": [
{
"files": ["*.js"],
"files": [
"*.js"
],
"rules": {
"no-console": "warn"
}
},
{
"files": ["*.{js,jsx}"],
"files": [
"*.{js,jsx}"
],
"env": {
"es2024": true
},
"globals": {
"ReadFoo": "readonly",
"WriteBar": "writeable",
"NonBaz": "off"
},
"rules": {
"no-console": "off"
}
},
{
"files": ["*.ts"],
"files": [
"*.ts"
],
"env": {
"es2024": false
},
"globals": {
"DefaultFoo": "off"
},
"rules": {
"no-console": "warn"
}
}
]
}
}
31 changes: 27 additions & 4 deletions apps/oxlint/fixtures/overrides/directories-config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
{
"globals": {
"DefaultFoo": "readonly"
},
"rules": {
"no-debugger": "off"
"no-debugger": "off",
"no-global-assign": "error"
},
"overrides": [
{
"files": ["lib/*.{js,ts}", "src/*"],
"files": [
"lib/*.{js,ts}",
"src/*"
],
"env": {
"es2024": true
},
"globals": {
"ReadFoo": "readonly",
"WriteBar": "writeable",
"NonBaz": "off"
},
"rules": {
"no-debugger": "error"
}
},
{
"files": ["**/tests/*"],
"files": [
"**/tests/*"
],
"env": {
"es2024": false
},
"globals": {
"DefaultFoo": "off"
},
"rules": {
"no-debugger": "warn"
}
}
]
}
}
7 changes: 7 additions & 0 deletions apps/oxlint/fixtures/overrides/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
debugger;

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
7 changes: 7 additions & 0 deletions apps/oxlint/fixtures/overrides/lib/tests/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
debugger;

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
7 changes: 7 additions & 0 deletions apps/oxlint/fixtures/overrides/other.jsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var msg = "hello";
console.log(msg);

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
8 changes: 8 additions & 0 deletions apps/oxlint/fixtures/overrides/src/oxlint.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// for rules detection
debugger;

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
8 changes: 8 additions & 0 deletions apps/oxlint/fixtures/overrides/src/tests/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// for rules detection
debugger;

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
7 changes: 7 additions & 0 deletions apps/oxlint/fixtures/overrides/test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var msg = "hello";
console.log(msg);

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
7 changes: 7 additions & 0 deletions apps/oxlint/fixtures/overrides/test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var msg = "hello";
console.log(msg);

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,33 @@ working directory:
`----
help: Replace var with let or const
Found 0 warnings and 1 error.
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/test.js:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'DefaultFoo' should not be modified.
,-[fixtures/overrides/test.js:8:1]
7 | // for globals detection
8 | DefaultFoo = 'defaultReadable';
: ^^^^^|^^^^
: `-- Read-only global 'DefaultFoo' should not be modified.
9 | ReadFoo = 'readable';
`----
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'ReadFoo' should not be modified.
,-[fixtures/overrides/test.js:9:1]
8 | DefaultFoo = 'defaultReadable';
9 | ReadFoo = 'readable';
: ^^^|^^^
: `-- Read-only global 'ReadFoo' should not be modified.
`----
Found 0 warnings and 4 errors.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand All @@ -38,10 +64,20 @@ working directory:
1 | var msg = "hello";
2 | console.log(msg);
: ^^^^^^^^^^^
3 |
`----
help: Delete this console statement.
Found 1 warning and 1 error.
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/test.ts:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----
Found 1 warning and 2 errors.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand All @@ -60,7 +96,33 @@ working directory:
`----
help: Replace var with let or const
Found 0 warnings and 1 error.
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/other.jsx:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'DefaultFoo' should not be modified.
,-[fixtures/overrides/other.jsx:8:1]
7 | // for globals detection
8 | DefaultFoo = 'defaultReadable';
: ^^^^^|^^^^
: `-- Read-only global 'DefaultFoo' should not be modified.
9 | ReadFoo = 'readable';
`----
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'ReadFoo' should not be modified.
,-[fixtures/overrides/other.jsx:9:1]
8 | DefaultFoo = 'defaultReadable';
9 | ReadFoo = 'readable';
: ^^^|^^^
: `-- Read-only global 'ReadFoo' should not be modified.
`----
Found 0 warnings and 4 errors.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand Down
Loading

0 comments on commit 4c309f2

Please sign in to comment.