Skip to content

Commit

Permalink
build: integrate eslint, stylelint, prettier, lint-staged, commitlint
Browse files Browse the repository at this point in the history
  • Loading branch information
tjx666 committed Feb 4, 2020
1 parent 1449f01 commit 3c14139
Show file tree
Hide file tree
Showing 7 changed files with 5,464 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
// 暂时定为默认值,根据自己的需求调整
['build', 'ci', 'chore', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'],
],
},
};
78 changes: 78 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const { resolve } = require('path');

module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: ['plugin:react/recommended', 'airbnb', 'airbnb/hooks', 'prettier'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2020,
sourceType: 'module',
},
settings: {
'import/resolver': {
node: {
// 指定 eslint-plugin-import 解析的后缀名
extensions: ['.ts', '.tsx', '.js', '.json'],
},
// 配置 eslint-import-resolver-typescript 读取 tsconfig.json 的路径
typescript: {
directory: [resolve(__dirname, './src/tsconfig.json'), resolve(__dirname, './scripts/tsconfig.json')],
},
},
},
plugins: ['react', '@typescript-eslint'],
rules: {
'import/extensions': [
'error',
'ignorePackages',
{
ts: 'never',
tsx: 'never',
json: 'never',
js: 'never',
},
],

'@typescript-eslint/no-useless-constructor': 'error',

'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }],
'react/jsx-indent-props': ['error', 4],
'react/jsx-indent': ['error', 4],

'func-names': 'off',
'lines-between-class-members': 'off',
'no-console': 'off',
'no-empty': 'warn',
'no-param-reassign': 'warn',
'no-plusplus': 'off',
'no-unused-expressions': 'off',
'no-unused-vars': 'warn',
'no-useless-constructor': 'off',
},
overrides: [
{
files: ['**/*.d.ts'],
rules: {
'import/no-duplicates': 'off',
'max-classes-per-file': 'off',
},
},
{
files: ['scripts/**/*.ts'],
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
],
};
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"trailingComma": "all",
"tabWidth": 4,
"semi": true,
"singleQuote": true,
"endOfLine": "auto",
"printWidth": 120,
"overrides": [
{
"files": "*.md",
"options": {
"tabWidth": 2
}
}
]
}
12 changes: 12 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["stylelint-config-standard", "stylelint-config-rational-order", "stylelint-config-prettier"],
"plugins": ["stylelint-order", "stylelint-declaration-block-no-ignored-properties"],
"rules": {
"comment-empty-line-before": null,
"declaration-empty-line-before": null,
"function-name-case": "lower",
"no-descending-specificity": null,
"no-invalid-double-slash-comments": null
},
"ignoreFiles": ["node_modules/**/*", "src/assets/**/*", "dist/**/*", "**/typings/**/*"]
}
Empty file added CHANGELOG.md
Empty file.
48 changes: 47 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,52 @@
},
"license": "MIT",
"scripts": {
"test": "echo 'skip test...'"
"test": "echo 'skip test...'",
"lint": "yarn run lint-eslint && yarn run lint-stylelint",
"lint-eslint": "eslint -c .eslintrc.js --ext .ts,.tsx,.js {src,scripts}/**/*.{ts,tsx,js}",
"lint-stylelint": "stylelint --config .stylelintrc.json src/**/*.scss --syntax scss",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -c .commitlintrc.js -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.{ts,tsx,js}": [
"eslint -c .eslintrc.js"
],
"*.scss": [
"stylelint --config .stylelintrc.json"
],
"*.{ts,tsx,js,json,scss,md}": [
"prettier --write"
]
},
"dependencies": {},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"conventional-changelog-cli": "^2.0.31",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.10.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^2.3.0",
"husky": "^4.2.1",
"lint-staged": "^10.0.7",
"prettier": "^1.19.1",
"stylelint": "^13.0.0",
"stylelint-config-prettier": "^8.0.1",
"stylelint-config-rational-order": "^0.1.2",
"stylelint-config-standard": "^19.0.0",
"stylelint-declaration-block-no-ignored-properties": "^2.2.0",
"stylelint-order": "^4.0.0"
}
}
Loading

0 comments on commit 3c14139

Please sign in to comment.