fix: get the real filename to avoid rule invalidation #1852
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.
Checklist
Tell us about your environment
Please show your full configuration:
What did you do?
Our projects are migrating from JS to TS in stages, at the stage where Vue files exist with both languages, it is difficult to set up an ESLint configuration that includes TS rules, so i rename
.vue
file withlang="js"
to.jsvue
code-block through the eslint-plugin'spreprocess
hook, then we can apply the rules separately.What did you expect to happen?
I hope the
eslint-plugin-vue
can verify the.jsvue
code-block normally, because i specified that the.jsvue
code-block is parsed with thevue-eslint-parser
.What actually happened?
The following rules are invalid
vue/require-direct-export
vue/multi-word-component-names
vue/html-indent
Why this happened?
Because the
eslint-plugin-vue
use thecontext.getFilename()
to get the filename, and uses it as a condition for judging whether it is a Vue file, but exceptions may be caused in the following cases:Use the eslint-plugin's
preprocess
hook to rename the code-block:Use the ESLint CLI to lint text, in this case, the filename obtained by
context.getFilename()
is<input>
or<text>
, if not specified.How to fix
Since [email protected], the
context.getPhysicalFilename()
method is provided to the user to obtain t the full path of the file on disk without any code block information, we can use thecontext.getPhysicalFilename()
method to avoid misjudging the file as not a Vue file.References