umi生成项目时自带添加了lint相关npm包
1.增加script中指令
"lint": "umi g tmp && npm run lint:js && npm run lint:style && npm run lint:prettier",
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint:prettier": "prettier --check \"src/**/*\" --end-of-line auto",
"lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
"prettier": "prettier -c --write \"src/**/*\"",
"precommit": "lint-staged",
"precommit:fix": "npm run lint:fix && npm run prettier && npm run lint:prettier && npm run lint:style"
2.lint-staged部分:
"**/*.less": "stylelint --syntax less",
"**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js",
"*.{ts,tsx}": "npm run lint-staged:js",
"*.{js,jsx}": "npm run lint-staged:js"
3.新建package.json同级目录文件 .stylelintrc.js
const fabric = require('@umijs/fabric');
module.exports = {
...fabric.stylelint,
};
npm run /yarn precommit:fix