Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/oxlint/test/fixtures/definePlugin/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"define-plugin-plugin/create-once-before-false": "error",
"define-plugin-plugin/create-once-before-only": "error",
"define-plugin-plugin/create-once-after-only": "error",
"define-plugin-plugin/create-once-hooks-only": "error",
"define-plugin-plugin/create-once-no-hooks": "error"
}
}
1 change: 1 addition & 0 deletions apps/oxlint/test/fixtures/definePlugin/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default [
'define-plugin-plugin/create-once-before-false': 'error',
'define-plugin-plugin/create-once-before-only': 'error',
'define-plugin-plugin/create-once-after-only': 'error',
'define-plugin-plugin/create-once-hooks-only': 'error',
'define-plugin-plugin/create-once-no-hooks': 'error',
},
},
Expand Down
10 changes: 9 additions & 1 deletion apps/oxlint/test/fixtures/definePlugin/eslint.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ filename: files/1.js define-plugin-plugin/create-once
filename: files/1.js define-plugin-plugin/create-once-before-false
0:1 error before hook:
filename: files/1.js define-plugin-plugin/create-once-before-only
0:1 error before hook:
filename: files/1.js define-plugin-plugin/create-once-hooks-only
0:1 error after hook:
identNum: 2
filename: files/1.js define-plugin-plugin/create-once
0:1 error after hook:
filename: files/1.js define-plugin-plugin/create-once-after-only
0:1 error after hook:
filename: files/1.js define-plugin-plugin/create-once-hooks-only
1:5 error ident visit fn "a":
filename: files/1.js define-plugin-plugin/create
1:5 error ident visit fn "a":
Expand Down Expand Up @@ -53,13 +57,17 @@ filename: files/2.js define-plugin-plugin/create-once
filename: files/2.js define-plugin-plugin/create-once-before-false
0:1 error before hook:
filename: files/2.js define-plugin-plugin/create-once-before-only
0:1 error before hook:
filename: files/2.js define-plugin-plugin/create-once-hooks-only
0:1 error after hook:
identNum: 2
filename: files/2.js define-plugin-plugin/create-once
0:1 error after hook:
filename: files/2.js define-plugin-plugin/create-once-before-false
0:1 error after hook:
filename: files/2.js define-plugin-plugin/create-once-after-only
0:1 error after hook:
filename: files/2.js define-plugin-plugin/create-once-hooks-only
1:5 error ident visit fn "c":
filename: files/2.js define-plugin-plugin/create
1:5 error ident visit fn "c":
Expand Down Expand Up @@ -87,7 +95,7 @@ filename: files/2.js define-plugin-plugin
1:8 error ident visit fn "d":
filename: files/2.js define-plugin-plugin/create-once-no-hooks

35 problems (35 errors, 0 warnings)
39 problems (39 errors, 0 warnings)
```

# stderr
Expand Down
30 changes: 29 additions & 1 deletion apps/oxlint/test/fixtures/definePlugin/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
: ^
`----

x define-plugin-plugin(create-once-hooks-only): before hook:
| filename: files/1.js
,-[files/1.js:1:1]
1 | let a, b;
: ^
`----

x define-plugin-plugin(create-once-hooks-only): after hook:
| filename: files/1.js
,-[files/1.js:1:1]
1 | let a, b;
: ^
`----

x define-plugin-plugin(create): ident visit fn "a":
| filename: files/1.js
,-[files/1.js:1:5]
Expand Down Expand Up @@ -172,6 +186,20 @@
: ^
`----

x define-plugin-plugin(create-once-hooks-only): before hook:
| filename: files/2.js
,-[files/2.js:1:1]
1 | let c, d;
: ^
`----

x define-plugin-plugin(create-once-hooks-only): after hook:
| filename: files/2.js
,-[files/2.js:1:1]
1 | let c, d;
: ^
`----

x define-plugin-plugin(create): ident visit fn "c":
| filename: files/2.js
,-[files/2.js:1:5]
Expand Down Expand Up @@ -258,7 +286,7 @@
: ^
`----

Found 0 warnings and 35 errors.
Found 0 warnings and 39 errors.
Finished in Xms on 2 files using X threads.
```

Expand Down
24 changes: 23 additions & 1 deletion apps/oxlint/test/fixtures/definePlugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const createOnceBeforeFalseRule: Rule = {
},
};

// These 3 rules test that `createOnce` without `before` and `after` hooks works correctly.
// These 4 rules test that `createOnce` without `before` and `after` hooks works correctly.

const createOnceBeforeOnlyRule: Rule = {
createOnce(context) {
Expand Down Expand Up @@ -183,6 +183,27 @@ const createOnceAfterOnlyRule: Rule = {
},
};

const createOnceHooksOnlyRule: Rule = {
createOnce(context) {
return {
before() {
context.report({
message: 'before hook:\n' +
`filename: ${relativePath(context.filename)}`,
node: SPAN,
});
},
after() {
context.report({
message: 'after hook:\n' +
`filename: ${relativePath(context.filename)}`,
node: SPAN,
});
},
};
},
};

const createOnceNoHooksRule: Rule = {
createOnce(context) {
return {
Expand All @@ -207,6 +228,7 @@ export default definePlugin({
'create-once-before-false': createOnceBeforeFalseRule,
'create-once-before-only': createOnceBeforeOnlyRule,
'create-once-after-only': createOnceAfterOnlyRule,
'create-once-hooks-only': createOnceHooksOnlyRule,
'create-once-no-hooks': createOnceNoHooksRule,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"define-plugin-and-rule-plugin/create-once-before-false": "error",
"define-plugin-and-rule-plugin/create-once-before-only": "error",
"define-plugin-and-rule-plugin/create-once-after-only": "error",
"define-plugin-and-rule-plugin/create-once-hooks-only": "error",
"define-plugin-and-rule-plugin/create-once-no-hooks": "error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default [
'define-plugin-and-rule-plugin/create-once-before-false': 'error',
'define-plugin-and-rule-plugin/create-once-before-only': 'error',
'define-plugin-and-rule-plugin/create-once-after-only': 'error',
'define-plugin-and-rule-plugin/create-once-hooks-only': 'error',
'define-plugin-and-rule-plugin/create-once-no-hooks': 'error',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ filename: files/1.js define-plugin-and-rule-plugin/create-once
filename: files/1.js define-plugin-and-rule-plugin/create-once-before-false
0:1 error before hook:
filename: files/1.js define-plugin-and-rule-plugin/create-once-before-only
0:1 error before hook:
filename: files/1.js define-plugin-and-rule-plugin/create-once-hooks-only
0:1 error after hook:
identNum: 2
filename: files/1.js define-plugin-and-rule-plugin/create-once
0:1 error after hook:
filename: files/1.js define-plugin-and-rule-plugin/create-once-after-only
0:1 error after hook:
filename: files/1.js define-plugin-and-rule-plugin/create-once-hooks-only
1:5 error ident visit fn "a":
filename: files/1.js define-plugin-and-rule-plugin/create
1:5 error ident visit fn "a":
Expand Down Expand Up @@ -53,13 +57,17 @@ filename: files/2.js define-plugin-and-rule-plugin/create-once
filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false
0:1 error before hook:
filename: files/2.js define-plugin-and-rule-plugin/create-once-before-only
0:1 error before hook:
filename: files/2.js define-plugin-and-rule-plugin/create-once-hooks-only
0:1 error after hook:
identNum: 2
filename: files/2.js define-plugin-and-rule-plugin/create-once
0:1 error after hook:
filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false
0:1 error after hook:
filename: files/2.js define-plugin-and-rule-plugin/create-once-after-only
0:1 error after hook:
filename: files/2.js define-plugin-and-rule-plugin/create-once-hooks-only
1:5 error ident visit fn "c":
filename: files/2.js define-plugin-and-rule-plugin/create
1:5 error ident visit fn "c":
Expand Down Expand Up @@ -87,7 +95,7 @@ filename: files/2.js define-plugin-and-ru
1:8 error ident visit fn "d":
filename: files/2.js define-plugin-and-rule-plugin/create-once-no-hooks

35 problems (35 errors, 0 warnings)
39 problems (39 errors, 0 warnings)
```

# stderr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
: ^
`----

x define-plugin-and-rule-plugin(create-once-hooks-only): before hook:
| filename: files/1.js
,-[files/1.js:1:1]
1 | let a, b;
: ^
`----

x define-plugin-and-rule-plugin(create-once-hooks-only): after hook:
| filename: files/1.js
,-[files/1.js:1:1]
1 | let a, b;
: ^
`----

x define-plugin-and-rule-plugin(create): ident visit fn "a":
| filename: files/1.js
,-[files/1.js:1:5]
Expand Down Expand Up @@ -172,6 +186,20 @@
: ^
`----

x define-plugin-and-rule-plugin(create-once-hooks-only): before hook:
| filename: files/2.js
,-[files/2.js:1:1]
1 | let c, d;
: ^
`----

x define-plugin-and-rule-plugin(create-once-hooks-only): after hook:
| filename: files/2.js
,-[files/2.js:1:1]
1 | let c, d;
: ^
`----

x define-plugin-and-rule-plugin(create): ident visit fn "c":
| filename: files/2.js
,-[files/2.js:1:5]
Expand Down Expand Up @@ -258,7 +286,7 @@
: ^
`----

Found 0 warnings and 35 errors.
Found 0 warnings and 39 errors.
Finished in Xms on 2 files using X threads.
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const createOnceBeforeFalseRule = defineRule({
},
});

// These 3 rules test that `createOnce` without `before` and `after` hooks works correctly.
// These 4 rules test that `createOnce` without `before` and `after` hooks works correctly.

const createOnceBeforeOnlyRule = defineRule({
createOnce(context) {
Expand Down Expand Up @@ -181,6 +181,27 @@ const createOnceAfterOnlyRule = defineRule({
},
});

const createOnceHooksOnlyRule = defineRule({
createOnce(context) {
return {
before() {
context.report({
message: 'before hook:\n' +
`filename: ${relativePath(context.filename)}`,
node: SPAN,
});
},
after() {
context.report({
message: 'after hook:\n' +
`filename: ${relativePath(context.filename)}`,
node: SPAN,
});
},
};
},
});

const createOnceNoHooksRule = defineRule({
createOnce(context) {
return {
Expand All @@ -205,6 +226,7 @@ export default definePlugin({
'create-once-before-false': createOnceBeforeFalseRule,
'create-once-before-only': createOnceBeforeOnlyRule,
'create-once-after-only': createOnceAfterOnlyRule,
'create-once-hooks-only': createOnceHooksOnlyRule,
'create-once-no-hooks': createOnceNoHooksRule,
},
});
1 change: 1 addition & 0 deletions apps/oxlint/test/fixtures/defineRule/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"define-rule-plugin/create-once-before-false": "error",
"define-rule-plugin/create-once-before-only": "error",
"define-rule-plugin/create-once-after-only": "error",
"define-rule-plugin/create-once-hooks-only": "error",
"define-rule-plugin/create-once-no-hooks": "error"
}
}
1 change: 1 addition & 0 deletions apps/oxlint/test/fixtures/defineRule/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default [
'define-rule-plugin/create-once-before-false': 'error',
'define-rule-plugin/create-once-before-only': 'error',
'define-rule-plugin/create-once-after-only': 'error',
'define-rule-plugin/create-once-hooks-only': 'error',
'define-rule-plugin/create-once-no-hooks': 'error',
},
},
Expand Down
10 changes: 9 additions & 1 deletion apps/oxlint/test/fixtures/defineRule/eslint.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ filename: files/1.js define-rule-plugin/create-once
filename: files/1.js define-rule-plugin/create-once-before-false
0:1 error before hook:
filename: files/1.js define-rule-plugin/create-once-before-only
0:1 error before hook:
filename: files/1.js define-rule-plugin/create-once-hooks-only
0:1 error after hook:
identNum: 2
filename: files/1.js define-rule-plugin/create-once
0:1 error after hook:
filename: files/1.js define-rule-plugin/create-once-after-only
0:1 error after hook:
filename: files/1.js define-rule-plugin/create-once-hooks-only
1:5 error ident visit fn "a":
filename: files/1.js define-rule-plugin/create
1:5 error ident visit fn "a":
Expand Down Expand Up @@ -53,13 +57,17 @@ filename: files/2.js define-rule-plugin/create-once
filename: files/2.js define-rule-plugin/create-once-before-false
0:1 error before hook:
filename: files/2.js define-rule-plugin/create-once-before-only
0:1 error before hook:
filename: files/2.js define-rule-plugin/create-once-hooks-only
0:1 error after hook:
identNum: 2
filename: files/2.js define-rule-plugin/create-once
0:1 error after hook:
filename: files/2.js define-rule-plugin/create-once-before-false
0:1 error after hook:
filename: files/2.js define-rule-plugin/create-once-after-only
0:1 error after hook:
filename: files/2.js define-rule-plugin/create-once-hooks-only
1:5 error ident visit fn "c":
filename: files/2.js define-rule-plugin/create
1:5 error ident visit fn "c":
Expand Down Expand Up @@ -87,7 +95,7 @@ filename: files/2.js define-rule-plugin/c
1:8 error ident visit fn "d":
filename: files/2.js define-rule-plugin/create-once-no-hooks

35 problems (35 errors, 0 warnings)
39 problems (39 errors, 0 warnings)
```

# stderr
Expand Down
Loading
Loading