-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Use custom parser for gts/gjs #1920
Conversation
c9bb26d
to
876e76d
Compare
.github/workflows/ci.yml
Outdated
@@ -17,7 +17,7 @@ jobs: | |||
strategy: | |||
matrix: | |||
os: [ ubuntu, windows ] | |||
node-version: [14.x, 16.x, 18.x] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of @typescript-eslint/scope-manager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This'll require a major release to drop node 14, cc @bmish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can also try to downgrade to 5.62.0.
They dropped 14 with the 6.0.0 release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i downgraded as i also needed lower version for testing with typed eslint
9ee801f
to
0ce038c
Compare
808c7bf
to
212d4d5
Compare
package.json
Outdated
"css-tree": "^2.0.4", | ||
"ember-rfc176-data": "^0.3.15", | ||
"ember-template-imports": "^3.4.2", | ||
"ember-template-recast": "^6.1.4", | ||
"ember-template-tag": "^2.2.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to not use content-tag
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content-tag only transforms the content. it does not provide any info about the changes done.
It also does not guarantee the same code syntax & spacing, as its not a recast and also adds import statement at the top, which changes all lines.
i tried also to use source mapping, but it doesn't matter if the syntax, semi & spacing is changed. which causes tokens to be different of the created AST. which is used by eslint to detect e.g. semi, spacing issues etc
c168c29
to
0128f9c
Compare
I don't think we can use content-tag unless it transforms a file into a useable form for linting. |
Anyone else who can review? @bmish ? |
0128f9c
to
f494221
Compare
06421d1
to
1bad26b
Compare
.github/workflows/ci.yml
Outdated
@@ -17,7 +17,7 @@ jobs: | |||
strategy: | |||
matrix: | |||
os: [ ubuntu, windows ] | |||
node-version: [14.x, 16.x, 18.x] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This'll require a major release to drop node 14, cc @bmish
const { templateVisitorKeys } = preprocessedResult; | ||
const visitorKeys = { ...result.visitorKeys, ...templateVisitorKeys }; | ||
result.isTypescript = isTypescript; | ||
convertAst(result, preprocessedResult, visitorKeys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that the template-lint rules could be added as eslint rules? I saw you had @glimmer/syntax
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I'm already having most of them working with this parser over at eslint-plugin-template-lint. running them natively. though only on my pc :)
and fixing is another issue. since template-lint works on ast. but block-indentation fixes things in a mixed way... and does trailing whitespace fixes, new line fixes, not just indentation
* @param preprocessedResult | ||
* @param visitorKeys | ||
*/ | ||
function convertAst(result, preprocessedResult, visitorKeys) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is all this code needed?
do we need to zip in the glimmer AST with the JS AST?
does doing so allow us to eventually phase out template-lint? (or adopt the rules in to here?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, possibly. but mostly now to auto-detect unused and undef vars. Also helps in existing rules as you saw:)
And later for eslint plugin template lint
@@ -380,6 +363,13 @@ module.exports = { | |||
currentClass.uses.add(name); | |||
} | |||
}, | |||
GlimmerPathExpression(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is much nicer!
"css-tree": "^2.0.4", | ||
"ember-rfc176-data": "^0.3.15", | ||
"ember-template-imports": "^3.4.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to see this gone
@@ -472,6 +499,40 @@ describe('lint errors on the exact line as the <template> tag', () => { | |||
}); | |||
}); | |||
|
|||
describe('supports eslint directives inside templtes', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('supports eslint directives inside templtes', () => { | |
describe('supports eslint directives inside templates', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
module.exports = { | ||
rules: requireIndex(`${__dirname}/rules`), | ||
configs: requireIndex(`${__dirname}/config`), | ||
utils: { | ||
ember: require('./utils/ember'), | ||
}, | ||
processors: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still probably want to export the parser -- @chancancode had a use case where the (now old) parser breaks on old code -- it'd be good for us to provide a way for folks to configure their own overrides in the lint config and set the parser:
overrides: [
{
files: ['modern/**/*.gts'],
parser: require('eslint-plugin-ember/gts-parser'),
// ...
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(we'd need to use package.json#exports
to expose this tho -- maybe for another PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or rather have an option to specify the internal base parser.
Now I'm just choosing between Babel parser and typescript eslint parser. But that could also be an option passed to the gts parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty file?
@@ -27,13 +30,28 @@ function initESLint(parser = '@babel/eslint-parser') { | |||
env: { | |||
browser: true, | |||
}, | |||
parser, | |||
parserOptions: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh i see how those files are used legit
13262a6
to
1932886
Compare
trailing spaces also work inside template tag, but they also remove them inside pre tag, textarea tag. |
1932886
to
8682c87
Compare
bonus: * enables type aware lints * prettier eslint plugin (with template tag prettier plugin) will just work for gts/gjs * can detect unused block params in templates * can detect undef vars in PathExpression * can add eslint directive comments in mustache or html disadvantage: * prettier will not work without template tag prettier plugin for gts/gjs files
8682c87
to
d6aa734
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this!
Bumped to this and I seem to get an eslint error at the very start of all of my This is defined within a class export class Alert extends Component<AlertSignature> {
<template> ... </template>
} I also get an error in all my TOC components
Any ideas? Relevant packages installed; |
@Techn1x do you have specified a parser in your eslint config? Like the typescript parser? |
@Techn1x can you open a separate issue to discuss this? @patricklx if this is a breaking change, we will need to revert it. |
Thanks, will do. |
This reverts commit 9bd5ee4.
This has been reverted in: |
I was writing this parser for eslint-plugin-template-lint,
but I think it makes sense to have it for the ember-plugin as well.
Also, as preprocess changes the filename to a virtual one, type aware linting will not work: typescript-eslint/typescript-eslint#6177 (comment)
By using a parser, that would be fixed
bonus:
disadvantage:
fixes #1770
fixes #1894
fixes #1747
fixes #1683
fixes #1659
also fixes ember-tooling/prettier-plugin-ember-template-tag#81
fixes ember-tooling/prettier-plugin-ember-template-tag#84
closes #1667