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 e5fe2a0
Show file tree
Hide file tree
Showing 18 changed files with 691 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"
}
}
]
}
}
10 changes: 10 additions & 0 deletions apps/oxlint/fixtures/overrides/other.jsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
var msg = "hello";
console.log(msg);

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'always-off';
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/overrides/src/oxlint.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// for rules detection
debugger;

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'always-off';
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/overrides/src/tests/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// for rules detection
debugger;

// for env detection
globalThis = 'abc';

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

// for env detection
globalThis = 'abc';

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

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultReadable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'always-off';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ working directory:
`----
help: Replace var with let or const
Found 0 warnings and 1 error.
! ]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 |
`----
Found 1 warning and 1 error.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand All @@ -38,10 +47,29 @@ working directory:
1 | var msg = "hello";
2 | console.log(msg);
: ^^^^^^^^^^^
3 |
`----
help: Delete this console statement.
Found 1 warning and 1 error.
! ]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 |
`----
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
,-[fixtures/overrides/test.ts:10:1]
9 | ReadFoo = 'readable';
10 | console.log(ReadFoo);
: ^^^^^^^^^^^
11 | WriteBar = 'writeable';
`----
help: Delete this console statement.
Found 3 warnings and 1 error.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand All @@ -60,7 +88,16 @@ working directory:
`----
help: Replace var with let or const
Found 0 warnings and 1 error.
! ]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 |
`----
Found 1 warning and 1 error.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand Down
105 changes: 105 additions & 0 deletions ....ts -c fixtures__overrides__.oxlintrc.json [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
source: apps/oxlint/src/tester.rs
assertion_line: 95
---
##########
arguments: -c fixtures/overrides/.oxlintrc.json fixtures/overrides/test.js
working directory:
----------

x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-var.html\eslint(no-var)]8;;\: Unexpected var, use let or const instead.
,-[fixtures/overrides/test.js:1:1]
1 | var msg = "hello";
: ^^^
2 | console.log(msg);
`----
help: Replace var with let or const

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 |
`----

Found 0 warnings and 2 errors.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------

##########
arguments: -c fixtures/overrides/.oxlintrc.json fixtures/overrides/test.ts
working directory:
----------

x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-var.html\eslint(no-var)]8;;\: Unexpected var, use let or const instead.
,-[fixtures/overrides/test.ts:1:1]
1 | var msg = "hello";
: ^^^
2 | console.log(msg);
`----
help: Replace var with let or const

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
,-[fixtures/overrides/test.ts:2:1]
1 | var msg = "hello";
2 | console.log(msg);
: ^^^^^^^^^^^
3 |
`----
help: Delete this console statement.

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 |
`----

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
,-[fixtures/overrides/test.ts:10:1]
9 | ReadFoo = 'readable';
10 | console.log(ReadFoo);
: ^^^^^^^^^^^
11 | WriteBar = 'writeable';
`----
help: Delete this console statement.

Found 2 warnings and 2 errors.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------

##########
arguments: -c fixtures/overrides/.oxlintrc.json fixtures/overrides/other.jsx
working directory:
----------

x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-var.html\eslint(no-var)]8;;\: Unexpected var, use let or const instead.
,-[fixtures/overrides/other.jsx:1:1]
1 | var msg = "hello";
: ^^^
2 | console.log(msg);
`----
help: Replace var with let or const

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 |
`----

Found 0 warnings and 2 errors.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Loading

0 comments on commit e5fe2a0

Please sign in to comment.