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
2 changes: 1 addition & 1 deletion .github/generated/ast_changes_watch_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ src:
- 'napi/parser/generated/deserialize/ts.js'
- 'napi/parser/generated/deserialize/ts_parent.js'
- 'napi/parser/generated/deserialize/ts_range.js'
- 'napi/parser/generated/deserialize/ts_range_no_parens.js'
- 'napi/parser/generated/deserialize/ts_range_parent.js'
- 'napi/parser/generated/deserialize/ts_range_parent_no_parens.js'
- 'napi/parser/generated/lazy/constructors.js'
- 'napi/parser/generated/lazy/types.js'
- 'napi/parser/generated/lazy/walk.js'
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const parserFilePaths = [
'generated/lazy/types.js',
'generated/lazy/walk.js',
*/
'generated/deserialize/ts_range_no_parens.js',
'generated/deserialize/ts_range_parent_no_parens.js',
'generated/visit/keys.js',
'generated/visit/types.js',
'generated/visit/visitor.d.ts',
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/src-js/plugins/source_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../generated/constants.js';
// @ts-expect-error we need to generate `.d.ts` file for this module
// We use the deserializer which removes `ParenthesizedExpression`s from AST to match ESLint
import { deserializeProgramOnly } from '../../dist/generated/deserialize/ts_range_no_parens.js';
import { deserializeProgramOnly } from '../../dist/generated/deserialize/ts_range_parent_no_parens.js';

import type { Program } from '@oxc-project/types';
import type { Scope, ScopeManager, Variable } from './scope.ts';
Expand Down
4 changes: 4 additions & 0 deletions apps/oxlint/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ describe('oxlint CLI', () => {
await testFixture('estree');
});

it('should receive AST with all nodes having `parent` property', async () => {
await testFixture('parent');
});

it('should receive data via `context`', async () => {
await testFixture('context_properties');
});
Expand Down
9 changes: 9 additions & 0 deletions apps/oxlint/test/fixtures/parent/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jsPlugins": ["./plugin.ts"],
"categories": {
"correctness": "off"
},
"rules": {
"parents/check": "error"
}
}
1 change: 1 addition & 0 deletions apps/oxlint/test/fixtures/parent/files/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const obj = { a: [b, c], ...d };
86 changes: 86 additions & 0 deletions apps/oxlint/test/fixtures/parent/output.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Exit code
1

# stdout
```
x parents(check): VariableDeclaration -> Program
,-[files/index.js:1:1]
1 | const obj = { a: [b, c], ...d };
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x parents(check): Program -> null
,-[files/index.js:1:1]
1 | const obj = { a: [b, c], ...d };
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x parents(check): Identifier -> VariableDeclarator
,-[files/index.js:1:7]
1 | const obj = { a: [b, c], ...d };
: ^^^
`----

x parents(check): VariableDeclarator -> VariableDeclaration
,-[files/index.js:1:7]
1 | const obj = { a: [b, c], ...d };
: ^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x parents(check): ObjectExpression -> VariableDeclarator
,-[files/index.js:1:13]
1 | const obj = { a: [b, c], ...d };
: ^^^^^^^^^^^^^^^^^^^
`----

x parents(check): Identifier -> Property
,-[files/index.js:1:15]
1 | const obj = { a: [b, c], ...d };
: ^
`----

x parents(check): Property -> ObjectExpression
,-[files/index.js:1:15]
1 | const obj = { a: [b, c], ...d };
: ^^^^^^^^^
`----

x parents(check): ArrayExpression -> Property
,-[files/index.js:1:18]
1 | const obj = { a: [b, c], ...d };
: ^^^^^^
`----

x parents(check): Identifier -> ArrayExpression
,-[files/index.js:1:19]
1 | const obj = { a: [b, c], ...d };
: ^
`----

x parents(check): Identifier -> ArrayExpression
,-[files/index.js:1:22]
1 | const obj = { a: [b, c], ...d };
: ^
`----

x parents(check): SpreadElement -> ObjectExpression
,-[files/index.js:1:26]
1 | const obj = { a: [b, c], ...d };
: ^^^^
`----

x parents(check): Identifier -> SpreadElement
,-[files/index.js:1:29]
1 | const obj = { a: [b, c], ...d };
: ^
`----

Found 0 warnings and 12 errors.
Finished in Xms on 1 file using X threads.
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
41 changes: 41 additions & 0 deletions apps/oxlint/test/fixtures/parent/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { Plugin } from '../../../dist/index.js';

const plugin: Plugin = {
meta: {
name: 'parents',
},
rules: {
check: {
create(context) {
return {
Program(node) {
context.report({ message: `${node.type} -> ${node.parent}`, node });
},
VariableDeclaration(node) {
context.report({ message: `${node.type} -> ${node.parent.type}`, node });
},
VariableDeclarator(node) {
context.report({ message: `${node.type} -> ${node.parent.type}`, node });
},
Identifier(node) {
context.report({ message: `${node.type} -> ${node.parent.type}`, node });
},
ObjectExpression(node) {
context.report({ message: `${node.type} -> ${node.parent.type}`, node });
},
Property(node) {
context.report({ message: `${node.type} -> ${node.parent.type}`, node });
},
ArrayExpression(node) {
context.report({ message: `${node.type} -> ${node.parent.type}`, node });
},
SpreadElement(node) {
context.report({ message: `${node.type} -> ${node.parent.type}`, node });
},
};
},
},
},
};

export default plugin;
Loading
Loading