-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for running prettier on script in Vue Single File Components #70
Conversation
Thanks for the PR. However, I'm confused about why it's necessary to add special logic to detect whether |
Hey, sorry, I wasn't sure what to include in the description. Let's start with example .vue file: <template>
<div id="app">
<h1>{{ msg }}</h1>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<style>
#app {
}
</style> How to lint or run prettier on script in this file? But that will soon not be possible if one will be interested in using official vue eslint plugin/config. It will use custom parser that understands not only script but also template part of the file allowing creation of eslint rules enforcing style in html. When this parser is used I was looking for relatively simple way to support running prettier on script in vue (in a universal, enforceable way, only other way is plugin for VS Code) and that lead me to playing with eslint-plugin-prettier and this PR. |
I see, thanks for clarifying. That said, I don't think it's a good idea for
I think it would be better if there was a solution for your problem that didn't involve making modifications to I maintain If we added a I'm imagining the API would look something like this, where const ruleComposer = require("eslint-rule-composer");
const SourceCode = require("eslint").SourceCode;
const eslintPluginPrettierRule = require("eslint-plugin-prettier").rules.prettier;
const enhancedPrettierRule = ruleComposer.mapSourceCode(
eslintPluginPrettierRule,
sourceCode => {
// do something vue-specific, such as extracting text from <script> tags
const scriptTagText = extractScriptTagText(sourceCode.text);
const scriptTagAst = extractScriptTagAst(sourceCode.ast);
return new SourceCode(scriptTagText, scriptTagAst);
}
);
// enhancedPrettierRule is now a new rule that preprocesses
// the AST and passes it to `eslint-plugin-prettier` Does that sound reasonable to you? I would accept a PR on |
Hey, thanks for long and comprehensive answer. The concept of |
In the next version of Prettier we'll support Vue components out-of-the-box, so this plugin should "just work" as-is. |
I've tried eslint-plugin-prettier with the latest prettier and found that it doesn't work. Perhaps this needs to be reopened? It doesnt work in the sense that eslint is still throwing errors on the template part of the vue file. |
You'll still need at least eslint-plugin-html I think? |
I have the same problems with Here is my current {
"extends": ["airbnb-base/legacy", "plugin:vue/recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"env": {
"browser": true,
"es6": true
},
"rules": {
"camelcase": "off",
"consistent-return": "off",
"guard-for-in": "off",
"no-extra-boolean-cast": "off",
"no-multi-assign": "off",
"no-nested-ternary": "off",
"no-param-reassign": "off",
"no-prototype-builtins": "off",
"no-shadow": "off",
"no-restricted-syntax": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off"
}
} |
@jackmu95 PR to fix that inbound 😄 Edit: #76 |
@azz Thanks for you investigations :) |
Hey,
It is intended to be used with upcoming vue-eslint-parser v2 that is used by upcoming eslint-plugin-vue v4.
You can find examples of .vue files in GitLab or OnsenUI.