All Projects → JowayYoung → vscode-lint

JowayYoung / vscode-lint

Licence: other
A VSCode configuration tool integrating Stylelint and Eslint

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vscode-lint

Husky.Net
Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
Stars: ✭ 394 (+556.67%)
Mutual labels:  stylelint, lint
Stylelint Config Primer
Sharable stylelint config used by GitHub's CSS
Stars: ✭ 165 (+175%)
Mutual labels:  stylelint, lint
eslint-config
An ESLint shareable config that I used in my projects
Stars: ✭ 15 (-75%)
Mutual labels:  lint, tslint
stylelint-config
Sharable stylelint config used by GitHub's CSS
Stars: ✭ 194 (+223.33%)
Mutual labels:  stylelint, lint
Express Webpack React Redux Typescript Boilerplate
🎉 A full-stack boilerplate that using express with webpack, react and typescirpt!
Stars: ✭ 156 (+160%)
Mutual labels:  stylelint, tslint
React Typescript Webpack2 Cssmodules Postcss
Simple Starter Template for React, TypeScript, postCSS, ITCSS, CSS-Modules, Webpack and Live Reloading (React Hot Loader 3)
Stars: ✭ 117 (+95%)
Mutual labels:  stylelint, tslint
stencil-boilerplate
A Stencil app boilerplate including routing, Redux etc.
Stars: ✭ 51 (-15%)
Mutual labels:  stylelint, tslint
lints
Lint all your JavaScript, CSS, HTML, Markdown and Dockerfiles with a single command
Stars: ✭ 14 (-76.67%)
Mutual labels:  stylelint, lint
react-typescript-boilerplate
A React + Redux + TypeScript + HOT + Webpack + Material-UI + Sass boilerplate
Stars: ✭ 18 (-70%)
Mutual labels:  stylelint, tslint
elint
A easy way to lint your code
Stars: ✭ 38 (-36.67%)
Mutual labels:  stylelint, lint
spec
🐣 easy to use eslint/stylelint/tslint/prettier/...
Stars: ✭ 60 (+0%)
Mutual labels:  stylelint, tslint
Stylelint Prettier
Stylelint plugin for Prettier formatting
Stars: ✭ 188 (+213.33%)
Mutual labels:  stylelint
Stylelint Config Recommended Scss
The recommended shareable SCSS config for stylelint
Stars: ✭ 141 (+135%)
Mutual labels:  stylelint
Nextjs Ts
Opinionated Next JS project boilerplate with TypeScript and Redux
Stars: ✭ 134 (+123.33%)
Mutual labels:  stylelint
Stylelint Config Recess Order
🗂️ Recess-based property sort order for Stylelint.
Stars: ✭ 133 (+121.67%)
Mutual labels:  stylelint
stylelint-problem-matcher
A GitHub Action that registers a problem matcher for Stylelint's report format
Stars: ✭ 18 (-70%)
Mutual labels:  stylelint
Stylefmt
stylefmt is a tool that automatically formats stylesheets.
Stars: ✭ 2,123 (+3438.33%)
Mutual labels:  stylelint
Barebones
A barebones boilerplate for getting started on a bespoke front end.
Stars: ✭ 127 (+111.67%)
Mutual labels:  stylelint
Frasco
Quick starter for Jekyll including full setup for Sass, PostCSS, Autoprefixer, stylelint, Webpack, ESLint, imagemin, Browsersync, etc.
Stars: ✭ 123 (+105%)
Mutual labels:  stylelint
Stylelint No Unsupported Browser Features
Disallow features that aren't supported by your target browser audience.
Stars: ✭ 238 (+296.67%)
Mutual labels:  stylelint

VSCode Lint

author version node npm test build coverage license

vscode-lint是一个集成StylelintEslint的VSCode配置工具,提供html/css/scss/less/js/ts/jsx/tsx/vue文件的代码校验功能

vscode-lint用于约束团队成员的编码规范编码风格,从而增加项目代码的可维护性可接入性,保障项目整体质量,可减少无用代码重复代码错误代码漏洞代码的产生几率。它的根本目的是一次部署全局运行,统一所有项目的编码规范编码风格,养成规范的码字习惯,减少不必要的错误与隐患。

vscode-lint依赖以下NPM模块的最新版本。

postcss babel typescript stylelint eslint eslint

为了方便表述,统一以下名词。

  • 以下提及的StylelintEslint都为VSCode插件
  • 以下提及的stylelinteslint都为NPM模块

安装

npm i -g vscode-lint

安装失败

  • 切换NPM镜像为淘宝镜像:npm config set registry https://registry.npmmirror.com/
  • 重新执行安装命令:npm i -g vscode-lint

配置

  • 打开VSCode
  • 选择左边工具栏插件,搜索并安装StylelintEslint,安装完毕重启VSCode
  • 选择文件→首选项→设置设置中可选用户工作区
    • 用户:配置生效后会作用于全局项目(若大部分项目都是单一的React应用或Vue应用推荐使用全局配置)
    • 工作区:配置生效后只会作用于当前打开项目
  • 点击设置右上角中间图标打开设置(json),打开的对应文件是settings.json
  • 插入以下配置并重启VSCode:为了保障每次修改完毕都能正常格式化代码,必须重启VSCode
{
	// 默认自定义配置
	"css.validate": false,
	"less.validate": false,
	"scss.validate": false,
	"editor.codeActionsOnSave": {
		"source.fixAll.eslint": true,
		"source.fixAll.stylelint": true
	},
	// 扩展自定义配置
	"eslint.nodePath": "path/vscode-lint/node_modules",
	"eslint.options": {
		"overrideConfigFile": "path/vscode-lint/eslint/eslintrc.js" // 可变⚠️
	},
	"stylelint.configBasedir": "path/vscode-lint",
	"stylelint.configFile": "path/vscode-lint/stylelint/stylelintrc.js",
	"stylelint.customSyntax": "postcss-html", // 可变⚠️
	"stylelint.stylelintPath": "path/vscode-lint/node_modules/stylelint",
	"stylelint.validate": ["html", "css", "scss", "less", "vue"]
}

以上配置的pathvscode-lint模块所在的NPM根目录,可执行npm config get prefix获取NPM根目录并替换path

  • 执行npm config get prefix获取的NPM根目录,例如是E:/Node/prefix/node_modules
  • 将上述配置的path替换为E:/Node/prefix/node_modules

请保持VSCode及其所有插件都为最新版本,防止因版本问题导致StylelintEslint失效。

结构

请根据项目自行选择以下配置文件。

Stylelint

校验不同类型代码需实时修改stylelint.customSyntax的值。

  • CSS/SCSSpostcss-scss
  • LESSpostcss-less
  • HTML/VUEpostcss-html

Eslint

校验不同类型代码需实时修改eslint.options.overrideConfigFile的值。

  • JSpath/vscode-lint/eslint/eslintrc.js
  • Reactpath/vscode-lint/eslint/eslintrc.react.js
  • Vuepath/vscode-lint/eslint/eslintrc.vue.js
  • TSpath/vscode-lint/tslint/tslintrc.js
  • React TSpath/vscode-lint/tslint/tslintrc.react.js
  • Vue TSpath/vscode-lint/tslint/tslintrc.vue.js

疑问

更新eslint到v6+就会失效

很多同学反映eslint 6+VSCode上失效,最高使用版本只能控制在v5.16.0。其实这本身就是配置问题,跟版本无关。本项目的eslint使用v8,只要配置正确就能正常使用。

上述安装行为使用了NPM,那么settings.jsoneslint.packageManager必须配置为npm(小写),但最新版本Eslint已默认此项,所以无需配置。若上述安装行为变成yarn global add vscode-lint,那么必须在settings.json中添加以下配置。

{
	"eslint.packageManager": "yarn"
}
首次安装Eslint并执行上述配置就会失效

首次安装Eslint可能会在js/ts/jsx/tsx/vue文件的控制台中看到以下警告。

Eslint is disabled since its execution has not been approved or denied yet. Use the light bulb menu to open the approval dialog.

说明Eslint被禁用了,虽然配置中无明确的禁用字段,但还是被禁用了。此时移步到VSCode右下角的工具栏,会看到禁用图标+ESLINT的标红按钮,单击它就会弹出一个弹框,选择Allow Everywhere就能启用Eslint的校验功能了。

版权

MIT © JowayYoung

后记

关注公众号IQ前端,一个专注于CSS/JS开发技巧的前端公众号,更多前端小干货等着你喔

IQ前端

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].