-
-
Notifications
You must be signed in to change notification settings - Fork 63
feat: Lint rule for unsupported js #2299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aleksanderkatan
wants to merge
36
commits into
main
Choose a base branch
from
feat/lint-rule-for-unsupported-js
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e253963
Implement rule
2bbe811
Update messages and reorder
09f1ff8
Clean up
226a7aa
Report assignment pattern
245154a
Add a rule for private identifiers
d92702f
Add missing tests
096069e
Reorder tests
bd32605
lint
2f38104
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan c40da2b
Potential fix for pull request finding
aleksanderkatan c55d427
Potential fix for pull request finding
aleksanderkatan e0c6bfb
Merge remote-tracking branch 'origin/main' into feat/lint-rule-for-un…
aleksanderkatan 471e7c2
Merge fixes
aleksanderkatan eba340b
Report eqeq
aleksanderkatan b2a1d91
Move tests
aleksanderkatan ebe784e
Update directiveTracking
aleksanderkatan 46867ea
Report functions
aleksanderkatan d595ca3
Omit reporting object methods
aleksanderkatan 97fbfb4
Update readme
aleksanderkatan 4247655
Report chain expression
aleksanderkatan d268b4b
Report ??
aleksanderkatan 51f780f
Report unsupported unary operators
aleksanderkatan 47cb18c
Update binary and unary operators
aleksanderkatan d264738
Better types
aleksanderkatan d78b9dd
Review fixes
aleksanderkatan a319001
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan e2a777b
Change from warn to error
aleksanderkatan 415579a
Merge remote-tracking branch 'origin/main' into feat/lint-rule-for-un…
aleksanderkatan 31b2905
Less getDirectiveStack calls
aleksanderkatan bda87f2
Review fixes
aleksanderkatan 0e39bd3
Report unsupported assignment expressions
aleksanderkatan 483b984
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan 8760085
Review fixes
aleksanderkatan 3c5f586
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan 788c52c
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan 7b5a9f2
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,24 @@ | ||
| import type { TSESLint } from '@typescript-eslint/utils'; | ||
| import { integerDivision } from './rules/integerDivision.ts'; | ||
| import { unwrappedPojos } from './rules/unwrappedPojos.ts'; | ||
| import { noUnsupportedSyntax } from './rules/noUnsupportedSyntax.ts'; | ||
|
|
||
| export const rules = { | ||
| 'integer-division': integerDivision, | ||
| 'unwrapped-pojo': unwrappedPojos, | ||
| 'no-unsupported-syntax': noUnsupportedSyntax, | ||
| } as const; | ||
|
|
||
| type Rules = Record<`typegpu/${keyof typeof rules}`, TSESLint.FlatConfig.RuleEntry>; | ||
|
|
||
| export const recommendedRules: Rules = { | ||
| 'typegpu/integer-division': 'warn', | ||
| 'typegpu/unwrapped-pojo': 'warn', | ||
| 'typegpu/no-unsupported-syntax': 'warn', | ||
| }; | ||
|
|
||
| export const allRules: Rules = { | ||
| 'typegpu/integer-division': 'error', | ||
| 'typegpu/unwrapped-pojo': 'error', | ||
| 'typegpu/no-unsupported-syntax': 'error', | ||
| }; |
202 changes: 202 additions & 0 deletions
202
packages/eslint-plugin/src/rules/noUnsupportedSyntax.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| import { TSESTree } from '@typescript-eslint/utils'; | ||
|
aleksanderkatan marked this conversation as resolved.
Outdated
|
||
| import { enhanceRule } from '../enhanceRule.ts'; | ||
| import { directiveTracking } from '../enhancers/directiveTracking.ts'; | ||
| import { createRule } from '../ruleCreator.ts'; | ||
|
|
||
| export const noUnsupportedSyntax = createRule({ | ||
| name: 'no-unsupported-syntax', | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: `Disallow JS syntax that will not be parsed to correct WGSL.`, | ||
| }, | ||
| messages: { | ||
| unsupportedSyntax: | ||
| "'{{snippet}}' will not parse to correct WGSL because it uses unsupported syntax: {{syntax}}.", | ||
| }, | ||
| schema: [], | ||
| }, | ||
| defaultOptions: [], | ||
|
|
||
| create: enhanceRule({ directives: directiveTracking }, (context, state) => { | ||
| const { directives } = state; | ||
|
|
||
| function report(node: TSESTree.Node, syntax: string) { | ||
| context.report({ | ||
| node, | ||
| messageId: 'unsupportedSyntax', | ||
| data: { snippet: context.sourceCode.getText(node), syntax }, | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| ArrowFunctionExpression() { | ||
| // TODO: needs to know if parent is inside useGpu | ||
| }, | ||
|
|
||
|
aleksanderkatan marked this conversation as resolved.
Outdated
|
||
| AssignmentPattern(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'assignment pattern (default parameter)'); | ||
| }, | ||
|
|
||
| AwaitExpression(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'await expression'); | ||
| }, | ||
|
|
||
| ClassDeclaration(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'class declaration'); | ||
| }, | ||
|
|
||
| ClassExpression(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'class expression'); | ||
| }, | ||
|
|
||
| DoWhileStatement(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'do-while loop'); | ||
| }, | ||
|
|
||
| ForInStatement(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'for-in loop'); | ||
| }, | ||
|
|
||
| FunctionDeclaration() { | ||
| // TODO: needs to know if parent is inside useGpu | ||
| }, | ||
|
aleksanderkatan marked this conversation as resolved.
Outdated
|
||
|
|
||
| FunctionExpression() { | ||
| // TODO: needs to know if parent is inside useGpu | ||
| }, | ||
|
aleksanderkatan marked this conversation as resolved.
Outdated
|
||
|
|
||
| Literal(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| if ('regex' in node && node.regex) { | ||
| report(node, 'regular expression literal'); | ||
| } | ||
| }, | ||
|
|
||
| NewExpression(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, `'new' expression`); | ||
| }, | ||
|
|
||
| PrivateIdentifier(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'private identifier'); | ||
| }, | ||
|
|
||
| Property(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| if (node.method) { | ||
| report(node, 'object method shorthand'); | ||
| } | ||
| if (node.computed) { | ||
| report(node, 'computed property key'); | ||
| } | ||
| }, | ||
|
|
||
| SequenceExpression(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'sequence expression (comma operator)'); | ||
| }, | ||
|
|
||
| SpreadElement(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'spread element'); | ||
| }, | ||
|
|
||
| SwitchStatement(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'switch statement'); | ||
| }, | ||
|
|
||
| TemplateLiteral(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'template literal'); | ||
| }, | ||
|
|
||
| ThrowStatement(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'throw statement'); | ||
| }, | ||
|
|
||
| TryStatement(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'try-catch statement'); | ||
| }, | ||
|
|
||
| UpdateExpression(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| if (node.prefix) { | ||
| report(node, 'prefix update expression'); | ||
| } | ||
| }, | ||
|
|
||
| VariableDeclaration(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| if (node.kind === 'var') { | ||
| report(node, `'var' declaration`); | ||
| } | ||
| if (node.declarations.length > 1) { | ||
| report(node, 'Multiple variable declarations in one statement'); | ||
|
aleksanderkatan marked this conversation as resolved.
Outdated
|
||
| } | ||
| }, | ||
|
|
||
| VariableDeclarator(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| if (node.id.type !== 'Identifier') { | ||
| report(node, 'variable declaration using destructuring'); | ||
| } | ||
| }, | ||
|
|
||
| YieldExpression(node) { | ||
| if (!directives.insideUseGpu()) { | ||
| return; | ||
| } | ||
| report(node, 'yield expression'); | ||
| }, | ||
| }; | ||
| }), | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.