8000 <style> block is treated as JS · Issue #15 · vuejs/vue-eslint-parser · GitHub
[go: up one dir, main page]

Skip to content

<style> block is treated as JS #15

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

8000 Closed
msokk opened this issue Aug 13, 2017 · 6 comments
Closed

<style> block is treated as JS #15

msokk opened this issue Aug 13, 2017 · 6 comments
Labels

Comments

@msokk
Copy link
msokk commented Aug 13, 2017

Hi,

After upgrading to eslint-plugin-vue v3 and finally figuring out to turn off eslint-plugin-html
, I got some max-lenerrors in style block - mostly background rules.

Is this expected that eslint-plugin-vue will lint CSS?

ESLint version: 4.4.1
eslint-plugin-vue: 3.11.0
vue-eslint-parser: 2.0.0-beta.6

@armano2
Copy link
Contributor
armano2 commented Aug 13, 2017

@msokk eslint-plugin-vue for now is not linting css, can you provide code to reproduce?

and your .eslintrc file

@armano2
Copy link
Contributor
armano2 commented Aug 13, 2017

eslint-plugin-html is parsing vue files than you can still use it but you have to change
"html/html-extensions": [".html"] to not include vue files

vuejs/eslint-plugin-vue#91 (comment)

@msokk
Copy link
Author
msokk commented Aug 13, 2017

Here is the code:
https://gist.github.com/msokk/99238890e19bc0208c950cea9d9aa0d8

I'm using airbnb eslint config, that's allowed with this plugin?

@armano2
Copy link
Contributor
armano2 commented Aug 13, 2017

ok i se where is an issue, right now parser is parsing entire code from file.
if we have:

<template></template>
<style>
div {
    background: red;
}
</style>

There is no AST from style but Tokens are there:
https://gist.github.com/armano2/b6c13f9dd2bdebb74fccb6b06e74cfce


rules witch inerate over Tokens are going to validate css/html/js (only stylistic rules)
in your case its: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/style.js#L151

'max-len': ['error', 100, 2, {
      ignoreUrls: true,
      ignoreComments: false,
      ignoreRegExpLiterals: true,
      ignoreStrings: true,
      ignoreTemplateLiterals: true,
}],

@mysticatea is this working as expected?

@mysticatea
Copy link
Member

Thank you for this issue.

However, this is one of known limitations.
The rule checks source code texts instead of AST trees, so lines which are on outside of <script> causes max-len errors.

There is no workaround for now. I can refactor the rule as using AST instead of texts.

As a side note, this plugin uses a different mechanism to eslint-plugin-html.

  • eslint-plugin-html is using preprocessors. It transforms source codes before parsers and rules use the source codes. In eslint-plugin-html case, it extracts only inside of <script>, then parsers and rules use it.
  • eslint-plugin-vue does not use the preprocessor. This parser parses whole source code of .vue files and rules use the whole source code. If eslint-plugin-vue uses the preprocessors, it removes outside of <script>, this parser cannot generate AST of <template>, so eslint-plugin-vue cannot use the preprocessors.

@msokk
Copy link
Author
msokk commented Aug 14, 2017

Thanks for clarifying.
I only got max-len errors and most of the affected rules can be spread over multiple lines and with airbnb config long urls are ignored. So overall I easily fixed those few max-len ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0