Note: This is a similar question to my previous question on the topic, which was left partly unsolved and after which the nature of the challenge changed considerably: How to configure Vue CLI 4 with ESLint + Prettier + Airbnb rules + TypeScript + Vetur?
In 2019 I was fairly obsessed by getting a 'holy grail' tooling setup configured with Vue in TypeScript and having VS Code to autofix your code on file save in .vue, .ts, and .scss files.
But getting Prettier to work optimally with ESLint and Vetur ended up being too much of a challenge. Because of an inherent clash with Prettier and ESLint having partly the same aim and similar rule checks, and with Vetur adding more complexity to this particular mix in VS Code.
Also when the setup was mostly working, it was rather irritating that you needed to save the file several times in a row. Because once ESLint found and fixed a set of errors, new errors appeared and it was not advanced enough to run those checks and fixes in a row until all was cleared...
In November 2019 I was attending Vue Conf Toronto, and in Mr. Evan's workshop Deep Dive with Vue 3.0 I got to ask him about this problem. He told that the official tooling is going to see major overhauling pretty soon, and there will be new features coming in from newer versions of ESLint...
He also hinted that at this point there is autofix logic written to nearly all of Vue's official Style Guide's rule checks, which in combination with the upcoming Vue 3.0 fully modular architecture may even see an official VS Code extension coming. Or at least is making it easier for Vetur and similar plugins to run code checks and fixes by leveraging these new capabilities.
In December 2019, Vue CLI 4.1 plugins and presets upgrades brought ESLint version 6 features on the table. Which meant we could start using ESLint not just as a linter, but also a formatter, effectively dropping the need for Prettier in our setups.
During the same time ESLint released version 2 of it's official VS Code extension dbaeumer.vscode-eslint, bringing in support for VS Code's Run Code Actions on save -feature, controlled by editor.codeActionsOnSave
-setting.
So finally the path was cleared for getting this setup running! Next up, I'll answer my own question on how to configure this mix.
PS. While it's possible Vetur could still be used as a part of this setup, here I've changed to using Stylelint. There has still been some problems with Stylelint's autofix feature, but is likely to be solved by future updates. Yet I'm still interested in hearing if Vetur would prove useful with or without Stylelint!
Official scaffolded Vue CLI project's configurations
After Vue CLI 4.2 upgrades in create project scaffolding in February 2020, you are half way through the configurations by creating a new project with global
vue create myproject
command and making at least these selections (configurations included below):Now you may be wondering why I chose
node-sass
over the first suggested optiondart-sass
− here's why: Vue CLI CSS pre-processor option: dart-sass VS node-sass?In
package.json
you are given at least these dependencies:With
.eslintrc.js
:With
.editorconfig
:Biased config changes for linting and formatting
So, with my biased modifications to
.eslintrc.js
:Then I've added
.eslintignore
file:Then I've added this section in top of
.editorconfig
(while not sure if this file is needed):Installing and configuring Stylelint
Stylelint is a somewhat similar project to CSS/SCSS/SASS/LESS/Stylus than ESLint is for JavaScript/TypeScript, being likewise extendable with plugins and presets. It has an official VS Code extension, and it can also be run during your Webpack build process.
I've chosen to extend Stylelint with stylelint-scss package, which currently has half a million of weekly downloads, and stylelint-config-recommended-scss package from the same maintainer. In addition, I've configured stylelint-webpack-plugin as a part of the Webpack build process.
Install these dev dependencies from the command line by:
npm i -D stylelint stylelint-config-recommended-scss stylelint-scss stylelint-webpack-plugin
Add a file
.stylelintrc.json
with a few biased rule modifications as an example (Vue's::v-deep
custom selector handling may come needed):Create file or add to
vue.config.js
, this some biased config examples:VS Code editor, extensions and settings
Create
.vscode
named folder in your project root for placing project specific settings and extension recommendations. Note that if you open VS Code in workspace mode (having multiple project roots included at once), some of the settings do not work in this mode, so I'm always opening the project root directly without using workspace mode.In this folder add a file
extensions.json
, with at least this content recommended, and install the extensions.Add another file
settings.json
with these or similar settings:So these were my biased project settings, and I'm interested in hearing improvement suggestions!