├── .gitignore ├── .npmignore ├── .prettierrc.js ├── README.md ├── README_CN.md ├── package.json ├── src ├── commitlint.ts ├── eslintReact.ts ├── eslintSvelte.ts ├── eslintVue2.ts ├── eslintVue3.ts ├── husky.ts ├── index.ts ├── lintstaged.ts ├── prettier.ts ├── stylelint.ts ├── tsEslintConfig.ts └── tsconfig.json ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | /node_modules/ 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | 3 | module.exports = { 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | printWidth: 100, 7 | proseWrap: 'never', 8 | endOfLine: 'lf', 9 | overrides: [ 10 | { 11 | files: '.prettierrc', 12 | options: { 13 | parser: 'json', 14 | }, 15 | }, 16 | { 17 | files: 'document.ejs', 18 | options: { 19 | parser: 'html', 20 | }, 21 | }, 22 | ], 23 | }; 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # code-specification-unid 2 | 3 | English | [简体中文](https://github.com/FE-PIRL/code-specification-unid/blob/master/README_CN.md) 4 | 5 | Produced to solve the problem of inconsistent code specifications for multiple projects in the team. 6 | 7 | It's a collection of unified configuration files including `prettier`, `eslint`, `stylelint`, `husky`, `lint-staged`, and `commitlint` support `react`、`vue2`、`vue3` and `svelte3`. 8 | 9 | [![NPM Version][npm-image]][npm-url] 10 | [![NPM Downloads][downloads-image]][downloads-url] 11 | [![License: MIT][license-image]][license-url] 12 | 13 | 14 | > * **eslint** helps you find js errors and improve the quality of js code 15 | > * **stylelint** helps you find css errors and improve the quality of css code 16 | > * **Prettier** helps you format the code, unify code format 17 | > * **Husky** and **lint-staged** run code inspections before submitting code to improve the quality of online code 18 | > * **commitlint** helps you unify the commit message format 19 | 20 | 21 | # Features 22 | 23 | * 🔖 All projects uniformly use an agreed code specification; 24 | * 📦 Put a large number of third-party dependencies back to simplify business code; 25 | * ✏️ On the basis of inheriting the unified specification, still provide customization capabilities; 26 | * 🏆 Support React, Vue2, Vue3 projects, and support file name verification; 27 | 28 | # Installation 29 | 30 | ``` 31 | npm install code-specification-unid --save-dev 32 | ``` 33 | Or 34 | 35 | ``` 36 | yarn add code-specification-unid -D 37 | ``` 38 | > Note: Since `code-specification-unid` has already consolidated most of the code specification-related dependency packages that may be used, there is no need to reinstall the following dependencies. 39 | If they are already installed, please delete them by yourself (including the corresponding configuration file): 40 | ```json 41 | "@babel/core": "^7.12.10", 42 | "@babel/eslint-parser": "^7.12.1", 43 | "@babel/plugin-proposal-class-properties": "^7.13.0", 44 | "@babel/plugin-proposal-decorators": "^7.13.5", 45 | "@babel/preset-env": "^7.12.11", 46 | "@babel/preset-react": "^7.12.10", 47 | "@babel/preset-typescript": "^7.12.7", 48 | "@commitlint/cli": "^11.0.0", 49 | "@commitlint/config-conventional": "^11.0.0", 50 | "@typescript-eslint/eslint-plugin": "^4.28.1", 51 | "@typescript-eslint/parser": "^4.28.1", 52 | "eslint": "^7.29.0", 53 | "eslint-config-prettier": "^8.3.0", 54 | "eslint-formatter-pretty": "^4.1.0", 55 | "eslint-plugin-babel": "^5.3.0", 56 | "eslint-plugin-compat": "^3.1.1", 57 | "eslint-plugin-eslint-comments": "^3.1.1", 58 | "eslint-plugin-filename": "^1.0.0", 59 | "eslint-plugin-import": "^2.17.3", 60 | "eslint-plugin-jest": "^24.0.1", 61 | "eslint-plugin-jsx-a11y": "^6.2.0", 62 | "eslint-plugin-markdown": "^1.0.0", 63 | "eslint-plugin-prettier": "^3.4.0", 64 | "eslint-plugin-promise": "^4.1.1", 65 | "eslint-plugin-react": "^7.22.0", 66 | "eslint-plugin-react-hooks": "^4.2.0", 67 | "eslint-plugin-svelte3": "^3.2.0", 68 | "eslint-plugin-unicorn": "^20.0.0", 69 | "eslint-plugin-vue": "^7.5.0", 70 | "husky": "^4.3.8", 71 | "lint-staged": "^10.5.3", 72 | "prettier": "^2.3.2", 73 | "prettier-plugin-svelte": "^2.2.0", 74 | "stylelint": "^13.7.0", 75 | "stylelint-config-css-modules": "^2.2.0", 76 | "stylelint-config-prettier": "^8.0.2", 77 | "stylelint-config-rational-order": "^0.1.2", 78 | "stylelint-config-standard": "^20.0.0", 79 | "stylelint-declaration-block-no-ignored-properties": "^2.1.0", 80 | "stylelint-no-unsupported-browser-features": "^4.1.4", 81 | "stylelint-order": "^4.0.0", 82 | "stylelint-prettier": "^1.1.2", 83 | "stylelint-scss": "^3.19.0" 84 | ``` 85 | 86 | # Configuration 87 | 88 | ### 1. Create configuration files as below; 89 | 90 | in `.eslintrc.js` 91 | 92 | ```js 93 | module.exports = { 94 | extends: [require.resolve('code-specification-unid/dist/eslintReact')], 95 | rules: { 96 | // your rules 97 | }, 98 | }; 99 | ``` 100 | 101 | > Note that for different projects, please import different eslint configuration packages 102 | > 103 | > react corresponds to `eslintReact` 104 | > 105 | > vue2 corresponds to `eslintVue2` 106 | > 107 | > vue3 corresponds to `eslintVue3` 108 | > 109 | > svelte corresponds to `eslintSvelte` 110 | 111 | in `.stylelintrc.js` 112 | 113 | ```js 114 | module.exports = { 115 | extends: [require.resolve('code-specification-unid/dist/stylelint')], 116 | rules: { 117 | // your rules 118 | }, 119 | }; 120 | ``` 121 | 122 | in `.prettierrc.js` 123 | 124 | ```js 125 | const spec = require('code-specification-unid'); 126 | 127 | module.exports = { 128 | ...spec.prettier, 129 | // your rules 130 | }; 131 | ``` 132 | 133 | in `.huskyrc.js` 134 | 135 | ```js 136 | const spec = require('code-specification-unid'); 137 | 138 | module.exports = { 139 | ...spec.husky, 140 | // your rules 141 | }; 142 | ``` 143 | 144 | in `.lintstagedrc.js` 145 | 146 | ```js 147 | const spec = require('code-specification-unid'); 148 | 149 | module.exports = { 150 | ...spec.lintstaged, 151 | // your rules 152 | }; 153 | ``` 154 | 155 | in `.commitlintrc.js` 156 | 157 | ```js 158 | const spec = require('code-specification-unid'); 159 | 160 | module.exports = { 161 | ...spec.commitlint, 162 | // your rules 163 | }; 164 | ``` 165 | 166 | > Note: The format types of submitted message are `'upd','feat','fix','refactor','docs','chore','style','revert'`, for example: `feat: add support for i18n` 167 | 168 | #### File name verification (optional) 169 | 170 | By default, file name verification does not require any configuration. The default rule is to support `camelcase` or `pascalcase` style file names. 171 | 172 | It relies on the [`eslint-plugin-filename`](https://github.com/benyasin/eslint-plugin-filename) plugin to complete, and supports two forms of alias and custom regular. 173 | 174 | The built-in aliases are `pascalcase`/`PascalCase`, `camelcase`/`camelCase`, `snakecase`/`snake_case`, `kebabcase`/`kebab-case`, 175 | It also supports passing in multiple aliases in the form of an array. 176 | 177 | E.g: 178 | 179 | ```js 180 | rules: { 181 | 'filename/match': [2, 'camelcase'], 182 | }, 183 | ``` 184 | 185 | Or 186 | 187 | ```js 188 | rules: { 189 | 'filename/match': [2, ['camelcase','pascalcase']], //default configuration 190 | }, 191 | ``` 192 | 193 | If the above built-in aliases cannot meet your needs, you can also customize regular expressions, for example: 194 | 195 | ```js 196 | 'filename/match': [2, /^([a-z]+-)*[a-z]+(?:\..*)?$/], 197 | ``` 198 | 199 | You can even use different rules for different file types, for example: 200 | 201 | ```js 202 | 'filename/match': [2, { '.js': 'camelCase', '.ts': /^([a-z]+-)*[a-z]+(?:\..*)?$/ }], 203 | ``` 204 | 205 | ### 2. Call command 206 | 207 | If it is a react project, add the following command to the script of your project package.json: 208 | ``` 209 | "lint": "npm run lint:js && npm run lint:css && npm run lint:format", 210 | "lint:js": "eslint src --fix --ext .js,.jsx,.ts,.tsx --cache --cache-location node_modules/.cache/eslint/", 211 | "lint:css": "stylelint --fix \"src/**/*.{less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/", 212 | "lint:format": "prettier --write \"src/**/*.{js,json,ts,tsx,css,less,scss,html,md}\"", 213 | ``` 214 | 215 | If it is a vue project, add the following command to the script of your project package.json: 216 | 217 | ``` 218 | "lint": "npm run lint:js && npm run lint:css && npm run lint:format", 219 | "lint:js": "eslint src --fix --ext .js,.jsx,.ts,.tsx,.vue --cache --cache-location node_modules/.cache/eslint/", 220 | "lint:css": "stylelint --fix \"src/**/*.{less,postcss,css,scss,vue}\" --cache --cache-location node_modules/.cache/stylelint/", 221 | "lint:format": "prettier --write \"src/**/*.{js,json,ts,tsx,vue,css,less,scss,html,md}\"", 222 | ``` 223 | 224 | If it is a svelte project, add the following command to the script of your project package.json: 225 | 226 | ``` 227 | "lint": "npm run lint:js && npm run lint:css && npm run lint:format", 228 | "lint:js": "eslint src --fix --ext .js,.jsx,.ts,.tsx,.svelte --cache --cache-location node_modules/.cache/eslint/", 229 | "lint:css": "stylelint --fix \"src/**/*.{less,postcss,css,scss,svelte}\" --cache --cache-location node_modules/.cache/stylelint/", 230 | "lint:format": "prettier --write \"src/**/*.{js,json,ts,tsx,svelte,css,less,scss,html,md}\"", 231 | ``` 232 | 233 | ### Usage example 234 | 235 | For a complete usage example, please refer to this [react-snowpack](https://github.com/benyasin/code-specification-unid-demo) example 236 | 237 | # Changelog 238 | 239 | 1.0.13 240 | 241 | * add supports for style order auto fixing 242 | 243 | 1.0.12 244 | 245 | * fix stylelint some default rules 246 | 247 | 1.0.11 248 | 249 | * add ESLint support for Typescript 3.8+ `import type` syntax 250 | 251 | 1.0.9 252 | 253 | * add stylelint-scss plugin 254 | 255 | 1.0.7 256 | 257 | * add supports for svelte 258 | 259 | 1.0.5 260 | 261 | * fix problem with filename validation expired when in vue project 262 | 263 | 1.0.3 264 | 265 | * add eslint ignore pattern for `.*.js` 266 | 267 | 1.0.0 268 | 269 | * Initial release 270 | 271 | 272 | # License 273 | 274 | MIT 275 | 276 | [npm-image]: https://img.shields.io/npm/v/code-specification-unid.svg?style=flat-square 277 | [npm-url]: https://npmjs.org/package/code-specification-unid 278 | [downloads-image]: https://img.shields.io/npm/dm/code-specification-unid.svg?style=flat-square 279 | [downloads-url]: https://npmjs.org/package/code-specification-unid 280 | [license-image]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square 281 | [license-url]: https://opensource.org/licenses/MIT 282 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # code-specification-unid 2 | 3 | 简体中文| [English](https://github.com/FE-PIRL/code-specification-unid/blob/master/README.md) 4 | 5 | 为了解决团队中多个项目代码规范不统一的问题而产生。 包含 `prettier`,`eslint`,`stylelint`, `husky`, `lint-staged`, `commitlint` 的统一配置文件合集, 支持`react`、`vue2`、`vue3` and `svelte3`. 6 | 7 | [![NPM Version][npm-image]][npm-url] 8 | [![NPM Downloads][downloads-image]][downloads-url] 9 | [![License: MIT][license-image]][license-url] 10 | 11 | > * **eslint** 帮你发现js错误,提高js代码质量 12 | > * **stylelint** 帮你发现css错误,提高css代码质量 13 | > * **prettier** 帮你格式化代码,统一代码格式 14 | > * **husky** 与**lint-staged** 在提交代码前进行代码检查,提高线上代码质量 15 | > * **commitlint** 帮你统一commit消息格式 16 | 17 | # 特性 18 | 19 | * 🔖 所有的项目统一使用一份约定好的代码规范; 20 | * 📦 将大量的第三方依赖模块后置以精简业务代码; 21 | * ✏️ 继承统一规范的基础上仍然提供个性化定制能力; 22 | * 🏆 支持React、Vue2、Vue3工程,且支持文件名校验; 23 | 24 | # 安装 25 | 26 | ``` 27 | npm install code-specification-unid --save-dev 28 | ``` 29 | 或者 30 | ``` 31 | yarn add code-specification-unid -D 32 | ``` 33 | 34 | > 注意:由于`code-specification-unid`依赖包已经对大部分可能用到的代码规范相关依赖包做了统一收敛,因此不需要再重新安装以下依赖,如果已经安装,请先自行删除(包括对应的配置文件): 35 | ```json 36 | "@babel/core": "^7.12.10", 37 | "@babel/eslint-parser": "^7.12.1", 38 | "@babel/plugin-proposal-class-properties": "^7.13.0", 39 | "@babel/plugin-proposal-decorators": "^7.13.5", 40 | "@babel/preset-env": "^7.12.11", 41 | "@babel/preset-react": "^7.12.10", 42 | "@babel/preset-typescript": "^7.12.7", 43 | "@commitlint/cli": "^11.0.0", 44 | "@commitlint/config-conventional": "^11.0.0", 45 | "@typescript-eslint/eslint-plugin": "^4.28.1", 46 | "@typescript-eslint/parser": "^4.28.1", 47 | "eslint": "^7.29.0", 48 | "eslint-config-prettier": "^8.3.0", 49 | "eslint-formatter-pretty": "^4.1.0", 50 | "eslint-plugin-babel": "^5.3.0", 51 | "eslint-plugin-compat": "^3.1.1", 52 | "eslint-plugin-eslint-comments": "^3.1.1", 53 | "eslint-plugin-filename": "^1.0.0", 54 | "eslint-plugin-import": "^2.17.3", 55 | "eslint-plugin-jest": "^24.0.1", 56 | "eslint-plugin-jsx-a11y": "^6.2.0", 57 | "eslint-plugin-markdown": "^1.0.0", 58 | "eslint-plugin-prettier": "^3.4.0", 59 | "eslint-plugin-promise": "^4.1.1", 60 | "eslint-plugin-react": "^7.22.0", 61 | "eslint-plugin-react-hooks": "^4.2.0", 62 | "eslint-plugin-svelte3": "^3.2.0", 63 | "eslint-plugin-unicorn": "^20.0.0", 64 | "eslint-plugin-vue": "^7.5.0", 65 | "husky": "^4.3.8", 66 | "lint-staged": "^10.5.3", 67 | "prettier": "^2.3.2", 68 | "prettier-plugin-svelte": "^2.2.0", 69 | "stylelint": "^13.7.0", 70 | "stylelint-config-css-modules": "^2.2.0", 71 | "stylelint-config-prettier": "^8.0.2", 72 | "stylelint-config-rational-order": "^0.1.2", 73 | "stylelint-config-standard": "^20.0.0", 74 | "stylelint-declaration-block-no-ignored-properties": "^2.1.0", 75 | "stylelint-no-unsupported-browser-features": "^4.1.4", 76 | "stylelint-order": "^4.0.0", 77 | "stylelint-prettier": "^1.1.2", 78 | "stylelint-scss": "^3.19.0" 79 | ``` 80 | 81 | # 配置 82 | 83 | ### 1. 创建以下配置文件,并按下面格式引入统一配置 84 | 85 | in `.eslintrc.js` 86 | 87 | ```js 88 | module.exports = { 89 | extends: [require.resolve('code-specification-unid/dist/eslintReact')], 90 | rules: { 91 | // your rules 92 | }, 93 | }; 94 | ``` 95 | 96 | > 注意针对不同工程,请引入不同的eslint配置包 97 | > 98 | > react 对应 `eslintReact` 99 | > 100 | > vue2 对应 `eslintVue2` 101 | > 102 | > vue3 对应 `eslintVue3` 103 | > 104 | > svelte 对应 `eslintSvelte` 105 | 106 | in `.stylelintrc.js` 107 | 108 | ```js 109 | module.exports = { 110 | extends: [require.resolve('code-specification-unid/dist/stylelint')], 111 | rules: { 112 | // your rules 113 | }, 114 | }; 115 | ``` 116 | 117 | in `.prettierrc.js` 118 | 119 | ```js 120 | const spec = require('code-specification-unid'); 121 | 122 | module.exports = { 123 | ...spec.prettier, 124 | // your rules 125 | }; 126 | ``` 127 | 128 | in `.huskyrc.js` 129 | 130 | ```js 131 | const spec = require('code-specification-unid'); 132 | 133 | module.exports = { 134 | ...spec.husky, 135 | // your rules 136 | }; 137 | ``` 138 | 139 | in `.lintstagedrc.js` 140 | 141 | ```js 142 | const spec = require('code-specification-unid'); 143 | 144 | module.exports = { 145 | ...spec.lintstaged, 146 | // your rules 147 | }; 148 | ``` 149 | 150 | in `.commitlintrc.js` 151 | 152 | ```js 153 | const spec = require('code-specification-unid'); 154 | 155 | module.exports = { 156 | ...spec.commitlint, 157 | // your rules 158 | }; 159 | ``` 160 | 161 | > 注意:提交消息的格式类型有` 'upd', 'feat', 'fix', 'refactor', 'docs', 'chore', 'style', 'revert'`, 比如:`feat: 添加国际化支持` 162 | 163 | #### 文件名校验(可选) 164 | 165 | 文件名校验在默认情况下,不需要做任何配置,默认规则是支持 `camelcase` 或 `pascalcase`风格的文件名。 166 | 167 | 它依赖 [`eslint-plugin-filename`](https://github.com/benyasin/code-specification-unid) 插件完成,支持别名与自定义正则两种形式。 168 | 169 | 内置的别名有 `pascalcase`/`PascalCase`, `camelcase`/`camelCase`, `snakecase`/`snake_case`, `kebabcase`/`kebab-case`, 170 | 还支持以数组的形式传入多个别名。 171 | 172 | 例如: 173 | 174 | ```js 175 | rules: { 176 | 'filename/match': [2, 'camelcase'], 177 | }, 178 | ``` 179 | 180 | 或 181 | 182 | ```js 183 | rules: { 184 | 'filename/match': [2, ['camelcase','pascalcase']], //此配置为默认配置 185 | }, 186 | ``` 187 | 如果上述内置的别名不能满足需求,你还可以自定义正则表达式,例如: 188 | 189 | ```js 190 | 'filename/match': [2, /^([a-z]+-)*[a-z]+(?:\..*)?$/], 191 | ``` 192 | 193 | 甚至可以针对不同的文件类型使用不同的规则,例如: 194 | 195 | ```js 196 | 'filename/match': [2, { '.js': 'camelCase', '.ts': /^([a-z]+-)*[a-z]+(?:\..*)?$/ }], 197 | ``` 198 | 199 | ### 2. 调用命令 200 | 201 | 如果是react项目,在你项目package.json的script中添加以下命令: 202 | ``` 203 | "lint": "npm run lint:js && npm run lint:css && npm run lint:format", 204 | "lint:js": "eslint src --fix --ext .js,.jsx,.ts,.tsx --cache --cache-location node_modules/.cache/eslint/", 205 | "lint:css": "stylelint --fix \"src/**/*.{less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/", 206 | "lint:format": "prettier --write \"src/**/*.{js,json,ts,tsx,css,less,scss,html,md}\"", 207 | ``` 208 | 209 | 如果是vue项目,在你项目package.json的script中添加以下命令: 210 | ``` 211 | "lint": "npm run lint:js && npm run lint:css && npm run lint:format", 212 | "lint:js": "eslint src --fix --ext .js,.jsx,.ts,.tsx,.vue --cache --cache-location node_modules/.cache/eslint/", 213 | "lint:css": "stylelint --fix \"src/**/*.{less,postcss,css,scss,vue}\" --cache --cache-location node_modules/.cache/stylelint/", 214 | "lint:format": "prettier --write \"src/**/*.{js,json,ts,tsx,vue,css,less,scss,html,md}\"", 215 | ``` 216 | 217 | 如果是svelte项目,在你项目package.json的script中添加以下命令: 218 | ``` 219 | "lint": "npm run lint:js && npm run lint:css && npm run lint:format", 220 | "lint:js": "eslint src --fix --ext .js,.jsx,.ts,.tsx,.svelte --cache --cache-location node_modules/.cache/eslint/", 221 | "lint:css": "stylelint --fix \"src/**/*.{less,postcss,css,scss,svelte}\" --cache --cache-location node_modules/.cache/stylelint/", 222 | "lint:format": "prettier --write \"src/**/*.{js,json,ts,tsx,svelte,css,less,scss,html,md}\"", 223 | ``` 224 | 225 | ### 使用示例 226 | 227 | 完整的使用示例可以参考这个[react-snowpack](https://github.com/benyasin/code-specification-unid-demo) 例子 228 | 229 | # 更新日志 230 | 231 | 1.0.13 232 | 233 | * 添加对样式排序自动修正的功能 234 | 235 | 1.0.12 236 | 237 | * 修正stylelint一些默认规则 238 | 239 | 1.0.11 240 | 241 | * 添加 eslint 对 typescript 3.8+ 新语法 `import type`的支持 242 | 243 | 1.0.9 244 | 245 | * 添加stylelint-scss插件 246 | 247 | 1.0.7 248 | 249 | * 添加对svelte的支持 250 | 251 | 1.0.5 252 | 253 | * 修复文件名校验在vue工程失效问题 254 | 255 | 1.0.3 256 | 257 | * 将`.*.js` 添加到eslint的忽略规则中 258 | 259 | 260 | 1.0.0 261 | 262 | * 初始发布 263 | 264 | # 协议 265 | 266 | MIT 267 | 268 | 269 | [npm-image]: https://img.shields.io/npm/v/code-specification-unid.svg?style=flat-square 270 | [npm-url]: https://npmjs.org/package/code-specification-unid 271 | [downloads-image]: https://img.shields.io/npm/dm/code-specification-unid.svg?style=flat-square 272 | [downloads-url]: https://npmjs.org/package/code-specification-unid 273 | [travis-image]: https://img.shields.io/travis/dolsem/code-specification-unid.svg?style=flat-square 274 | [travis-url]: https://travis-ci.org/dolsem/code-specification-unid 275 | [coverage-image]: https://img.shields.io/coveralls/dolsem/code-specification-unid.svg?style=flat-square 276 | [coverage-url]: https://coveralls.io/github/dolsem/code-specification-unid?branch=master 277 | [license-image]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square 278 | [license-url]: https://opensource.org/licenses/MIT 279 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code-specification-unid", 3 | "version": "1.0.13", 4 | "description": "A collection of configuration files containing prettier, eslint, stylelint, husky, lint-staged, commitlint", 5 | "keywords": [ 6 | "eslint", 7 | "prettier", 8 | "stylelint", 9 | "husky", 10 | "lint-staged", 11 | "commitlint" 12 | ], 13 | "homepage": "https://github.com/FE-PIRL/code-specification-unid#readme", 14 | "bugs": { 15 | "url": "https://github.com/FE-PIRL/code-specification-unid/issues" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com:FE-PIRL/code-specification-unid.git" 20 | }, 21 | "author": "benyasin", 22 | "license": "MIT", 23 | "main": "dist/index.js", 24 | "files": [ 25 | "dist" 26 | ], 27 | "scripts": { 28 | "build": "tsc --build tsconfig.json", 29 | "deps": "yarn upgrade-interactive --latest", 30 | "lib": "cross-env TIMING=1 eslint lib", 31 | "lint": "npm run build && cd example && npm run lint", 32 | "prettier": "prettier -c --write \"**/*\"" 33 | }, 34 | "dependencies": { 35 | "@babel/core": "^7.14.6", 36 | "@babel/eslint-parser": "^7.12.1", 37 | "@babel/plugin-proposal-class-properties": "^7.13.0", 38 | "@babel/plugin-proposal-decorators": "^7.13.5", 39 | "@babel/preset-env": "^7.12.11", 40 | "@babel/preset-react": "^7.12.10", 41 | "@babel/preset-typescript": "^7.12.7", 42 | "@commitlint/cli": "^11.0.0", 43 | "@commitlint/config-conventional": "^11.0.0", 44 | "@typescript-eslint/eslint-plugin": "^4.28.1", 45 | "@typescript-eslint/parser": "^4.28.1", 46 | "eslint": "^7.29.0", 47 | "eslint-config-prettier": "^8.3.0", 48 | "eslint-formatter-pretty": "^4.1.0", 49 | "eslint-plugin-babel": "^5.3.0", 50 | "eslint-plugin-compat": "^3.1.1", 51 | "eslint-plugin-eslint-comments": "^3.1.1", 52 | "eslint-plugin-filename": "^1.0.0", 53 | "eslint-plugin-import": "^2.17.3", 54 | "eslint-plugin-jest": "^24.0.1", 55 | "eslint-plugin-jsx-a11y": "^6.2.0", 56 | "eslint-plugin-markdown": "^1.0.0", 57 | "eslint-plugin-prettier": "^3.4.0", 58 | "eslint-plugin-promise": "^4.1.1", 59 | "eslint-plugin-react": "^7.22.0", 60 | "eslint-plugin-react-hooks": "^4.2.0", 61 | "eslint-plugin-svelte3": "^3.2.0", 62 | "eslint-plugin-unicorn": "^20.0.0", 63 | "eslint-plugin-vue": "^7.5.0", 64 | "husky": "^4.3.8", 65 | "lint-staged": "^10.5.3", 66 | "prettier": "^2.3.2", 67 | "prettier-plugin-svelte": "^2.2.0", 68 | "stylelint": "^13.7.0", 69 | "stylelint-config-css-modules": "^2.2.0", 70 | "stylelint-config-prettier": "^8.0.2", 71 | "stylelint-config-rational-order": "^0.1.2", 72 | "stylelint-config-standard": "^20.0.0", 73 | "stylelint-declaration-block-no-ignored-properties": "^2.1.0", 74 | "stylelint-no-unsupported-browser-features": "^4.1.4", 75 | "stylelint-order": "^4.1.0", 76 | "stylelint-prettier": "^1.1.2", 77 | "stylelint-scss": "^3.19.0", 78 | "typescript": "^4.0.2" 79 | }, 80 | "devDependencies": { 81 | "cross-env": "^7.0.3" 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/commitlint.ts: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | 3 | module.exports = { 4 | extends: [ 5 | "@commitlint/config-conventional" 6 | ], 7 | rules: { 8 | 'type-enum': [2, 'always', [ 9 | 'upd', 'feat', 'fix', 'refactor', 'docs', 'chore', 'style', 'revert' 10 | ]], 11 | 'type-case': [0], 12 | 'type-empty': [0], 13 | 'scope-empty': [0], 14 | 'scope-case': [0], 15 | 'subject-full-stop': [0, 'never'], 16 | 'subject-case': [0, 'never'], 17 | 'header-max-length': [0, 'always', 72] 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /src/eslintReact.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as fs from 'fs'; 3 | import tsEslintConfig from './tsEslintConfig'; 4 | 5 | const parserOptions = { 6 | ecmaVersion: 2020, 7 | sourceType: 'module', 8 | ecmaFeatures: { 9 | jsx: true, 10 | }, 11 | requireConfigFile: false, 12 | }; 13 | 14 | const isJsMoreTs = async (path = 'src') => { 15 | const fg = require('fast-glob'); 16 | const jsFiles = await fg(`${path}/src/**/*.{js,jsx}`, { deep: 3 }); 17 | const tsFiles = await fg(`${path}/src/**/*.{ts,tsx}`, { deep: 3 }); 18 | return jsFiles.length > tsFiles.length; 19 | }; 20 | 21 | const isTsProject = fs.existsSync(path.join(process.cwd() || '.', './tsconfig.json')); 22 | if (isTsProject) { 23 | try { 24 | isJsMoreTs(process.cwd()).then((jsMoreTs) => { 25 | if (!jsMoreTs) return; 26 | console.log('这是一个 TypeScript 项目,如果不是请删除 tsconfig.json'); 27 | }); 28 | } catch (e) { 29 | console.log(e); 30 | } 31 | } 32 | 33 | module.exports = { 34 | ignorePatterns: ['.*.js'], 35 | extends: ['plugin:react/recommended'] 36 | .concat( 37 | isTsProject ? ['plugin:@typescript-eslint/recommended'] : [], 38 | ) 39 | .concat(['prettier','plugin:prettier/recommended']), 40 | parser: isTsProject ? '@typescript-eslint/parser' : '@babel/eslint-parser', 41 | plugins: ['eslint-comments', 'react', 'jest', 'unicorn', 'react-hooks', 'filename'], 42 | env: { 43 | browser: true, 44 | node: true, 45 | es6: true, 46 | mocha: true, 47 | jest: true, 48 | jasmine: true, 49 | }, 50 | rules: { 51 | 'react/display-name': 0, 52 | 'react/jsx-props-no-spreading': 0, 53 | 'react/state-in-constructor': 0, 54 | 'react/static-property-placement': 0, 55 | // Too restrictive: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md 56 | 'react/destructuring-assignment': 'off', 57 | 'react/jsx-filename-extension': 'off', 58 | 'react/no-array-index-key': 'warn', 59 | 'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks 60 | 'react-hooks/exhaustive-deps': 'warn', // Checks deps of Hooks 61 | 'react/require-default-props': 0, 62 | 'react/jsx-fragments': 0, 63 | 'react/jsx-wrap-multilines': 0, 64 | 'react/prop-types': 0, 65 | 'react/forbid-prop-types': 0, 66 | 'react/sort-comp': 0, 67 | 'react/react-in-jsx-scope': 0, 68 | 'react/jsx-one-expression-per-line': 0, 69 | 'generator-star-spacing': 0, 70 | 'function-paren-newline': 0, 71 | 'import/no-unresolved': 0, 72 | 'import/order': 0, 73 | 'import/no-named-as-default': 0, 74 | 'import/no-cycle': 0, 75 | 'import/prefer-default-export': 0, 76 | 'import/no-default-export': 0, 77 | 'import/no-extraneous-dependencies': 0, 78 | 'import/named': 0, 79 | 'import/no-named-as-default-member': 0, 80 | 'import/no-duplicates': 0, 81 | 'import/no-self-import': 0, 82 | 'import/extensions': 0, 83 | 'import/no-useless-path-segments': 0, 84 | 'jsx-a11y/no-noninteractive-element-interactions': 0, 85 | 'jsx-a11y/click-events-have-key-events': 0, 86 | 'jsx-a11y/no-static-element-interactions': 0, 87 | 'jsx-a11y/anchor-is-valid': 0, 88 | 'sort-imports': 0, 89 | 'class-methods-use-this': 0, 90 | 'no-confusing-arrow': 0, 91 | 'linebreak-style': 0, 92 | // Too restrictive, writing ugly code to defend against a very unlikely scenario: https://eslint.org/docs/rules/no-prototype-builtins 93 | 'no-prototype-builtins': 'off', 94 | 'unicorn/prevent-abbreviations': 'off', 95 | // Conflict with prettier 96 | 'arrow-body-style': 0, 97 | 'arrow-parens': 0, 98 | 'object-curly-newline': 0, 99 | 'implicit-arrow-linebreak': 0, 100 | 'operator-linebreak': 0, 101 | 'eslint-comments/no-unlimited-disable': 0, 102 | 'no-param-reassign': 2, 103 | 'space-before-function-paren': 0, 104 | 'filename/match': [2, ['camelcase', 'pascalcase']], 105 | ...(isTsProject ? tsEslintConfig : {}), 106 | }, 107 | settings: { 108 | react: { 109 | pragma: 'React', 110 | version: 'detect', 111 | }, 112 | // support import modules from TypeScript files in JavaScript files 113 | 'import/resolver': { 114 | node: { 115 | extensions: isTsProject ? ['.js', '.jsx', '.ts', '.tsx', '.d.ts'] : ['.js', '.jsx'], 116 | }, 117 | }, 118 | 'import/parsers': { 119 | '@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'], 120 | }, 121 | 'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts'], 122 | 'import/external-module-folders': ['node_modules', 'node_modules/@types'], 123 | polyfills: ['fetch', 'Promise', 'URL', 'object-assign'], 124 | }, 125 | parserOptions: isTsProject ? Object.assign(parserOptions, { project: './tsconfig.json' }) : Object.assign(parserOptions, { 126 | babelOptions: { 127 | presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'], 128 | plugins: [ 129 | ['@babel/plugin-proposal-decorators', { legacy: true }], 130 | ['@babel/plugin-proposal-class-properties', { loose: true }], 131 | ], 132 | }, 133 | }), 134 | }; 135 | -------------------------------------------------------------------------------- /src/eslintSvelte.ts: -------------------------------------------------------------------------------- 1 | import tsEslintConfig from './tsEslintConfig'; 2 | import * as path from 'path'; 3 | import * as fs from 'fs'; 4 | 5 | const parserOptions = { 6 | allowImportExportEverywhere: true, 7 | ecmaVersion: 2020, 8 | sourceType: 'module', 9 | extraFileExtensions: ['.svelte'] 10 | }; 11 | 12 | const isJsMoreTs = async (path = 'src') => { 13 | const fg = require('fast-glob'); 14 | const jsFiles = await fg(`${path}/src/**/*.{js,jsx}`, { deep: 3 }); 15 | const tsFiles = await fg(`${path}/src/**/*.{ts,tsx}`, { deep: 3 }); 16 | return jsFiles.length > tsFiles.length; 17 | }; 18 | 19 | const isTsProject = fs.existsSync(path.join(process.cwd() || '.', './tsconfig.json')); 20 | if (isTsProject) { 21 | try { 22 | isJsMoreTs(process.cwd()).then((jsMoreTs) => { 23 | if (!jsMoreTs) return; 24 | console.log('这是一个 TypeScript 项目,如果不是请删除 tsconfig.json'); 25 | }); 26 | } catch (e) { 27 | console.log(e); 28 | } 29 | } 30 | 31 | module.exports = { 32 | ignorePatterns: ['.*.js'], 33 | extends: (isTsProject ? ['plugin:@typescript-eslint/recommended'] : ['eslint:recommended']), 34 | parser: isTsProject ? '@typescript-eslint/parser' : '@babel/eslint-parser', 35 | plugins: ['eslint-comments', 'jest', 'unicorn', 'filename', 'svelte3'], 36 | overrides: [ 37 | { 38 | files: ['**/*.svelte'], 39 | processor: 'svelte3/svelte3', 40 | }, 41 | ], 42 | env: { 43 | browser: true, 44 | node: true, 45 | es6: true, 46 | mocha: true, 47 | jest: true, 48 | jasmine: true, 49 | }, 50 | rules: { 51 | 'filename/match': [2, ['camelcase', 'pascalcase']], 52 | ...(isTsProject ? tsEslintConfig : {}), 53 | }, 54 | settings: { 55 | 'svelte3/typescript': require('typescript'), 56 | // ignore style tags in Svelte because of Tailwind CSS 57 | // See https://github.com/sveltejs/eslint-plugin-svelte3/issues/70 58 | 'svelte3/ignore-styles': () => true, 59 | // support import modules from TypeScript files in JavaScript files 60 | 'import/resolver': { 61 | node: { 62 | extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.svelte'], 63 | }, 64 | }, 65 | 'import/parsers': { 66 | '@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts', '.svelte'], 67 | }, 68 | 'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts', '.svelte'], 69 | 'import/external-module-folders': ['node_modules', 'node_modules/@types'], 70 | polyfills: ['fetch', 'Promise', 'URL', 'object-assign'], 71 | }, 72 | parserOptions: isTsProject ? Object.assign(parserOptions, { project: './tsconfig.json' }) : parserOptions, 73 | }; 74 | -------------------------------------------------------------------------------- /src/eslintVue2.ts: -------------------------------------------------------------------------------- 1 | import tsEslintConfig from './tsEslintConfig'; 2 | import * as path from 'path'; 3 | import * as fs from 'fs'; 4 | 5 | const parserOptions = { 6 | parser: '@typescript-eslint/parser', 7 | ecmaVersion: 2020, 8 | sourceType: 'module', 9 | ecmaFeatures: { 10 | jsx: true, 11 | }, 12 | extraFileExtensions: ['.vue'], 13 | }; 14 | 15 | const isJsMoreTs = async (path = 'src') => { 16 | const fg = require('fast-glob'); 17 | const jsFiles = await fg(`${path}/src/**/*.{js,jsx}`, { deep: 3 }); 18 | const tsFiles = await fg(`${path}/src/**/*.{ts,tsx}`, { deep: 3 }); 19 | return jsFiles.length > tsFiles.length; 20 | }; 21 | 22 | const isTsProject = fs.existsSync(path.join(process.cwd() || '.', './tsconfig.json')); 23 | if (isTsProject) { 24 | try { 25 | isJsMoreTs(process.cwd()).then((jsMoreTs) => { 26 | if (!jsMoreTs) return; 27 | console.log('这是一个 TypeScript 项目,如果不是请删除 tsconfig.json'); 28 | }); 29 | } catch (e) { 30 | console.log(e); 31 | } 32 | } 33 | 34 | module.exports = { 35 | ignorePatterns: ['.*.js'], 36 | extends: [ 37 | 'plugin:vue/base', 38 | 'plugin:vue/essential', 39 | 'plugin:vue/strongly-recommended', 40 | 'plugin:vue/recommended', 41 | ] 42 | .concat( 43 | isTsProject ? ['plugin:@typescript-eslint/recommended'] : [], 44 | ) 45 | .concat(['plugin:prettier/recommended']), 46 | parser: 'vue-eslint-parser', 47 | plugins: ['eslint-comments', 'jest', 'unicorn', 'filename'], 48 | env: { 49 | browser: true, 50 | node: true, 51 | es6: true, 52 | mocha: true, 53 | jest: true, 54 | jasmine: true, 55 | }, 56 | rules: { 57 | 'prettier/prettier': 'error', 58 | 'filename/match': [2, ['camelcase', 'pascalcase']], 59 | ...(isTsProject ? tsEslintConfig : {}), 60 | }, 61 | settings: { 62 | // support import modules from TypeScript files in JavaScript files 63 | 'import/resolver': { 64 | node: { 65 | extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.vue'], 66 | }, 67 | }, 68 | 'import/parsers': { 69 | '@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts', '.vue'], 70 | }, 71 | 'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts', '.vue'], 72 | 'import/external-module-folders': ['node_modules', 'node_modules/@types'], 73 | polyfills: ['fetch', 'Promise', 'URL', 'object-assign'], 74 | }, 75 | parserOptions: isTsProject ? Object.assign(parserOptions, { project: './tsconfig.json' }) : parserOptions, 76 | }; 77 | -------------------------------------------------------------------------------- /src/eslintVue3.ts: -------------------------------------------------------------------------------- 1 | import tsEslintConfig from './tsEslintConfig'; 2 | import * as path from 'path'; 3 | import * as fs from 'fs'; 4 | 5 | const parserOptions = { 6 | parser: '@typescript-eslint/parser', 7 | ecmaVersion: 2020, 8 | sourceType: 'module', 9 | ecmaFeatures: { 10 | jsx: true, 11 | }, 12 | extraFileExtensions: ['.vue'] 13 | }; 14 | 15 | const isJsMoreTs = async (path = 'src') => { 16 | const fg = require('fast-glob'); 17 | const jsFiles = await fg(`${path}/src/**/*.{js,jsx}`, { deep: 3 }); 18 | const tsFiles = await fg(`${path}/src/**/*.{ts,tsx}`, { deep: 3 }); 19 | return jsFiles.length > tsFiles.length; 20 | }; 21 | 22 | const isTsProject = fs.existsSync(path.join(process.cwd() || '.', './tsconfig.json')); 23 | if (isTsProject) { 24 | try { 25 | isJsMoreTs(process.cwd()).then((jsMoreTs) => { 26 | if (!jsMoreTs) return; 27 | console.log('这是一个 TypeScript 项目,如果不是请删除 tsconfig.json'); 28 | }); 29 | } catch (e) { 30 | console.log(e); 31 | } 32 | } 33 | 34 | module.exports = { 35 | ignorePatterns: ['.*.js'], 36 | extends: [ 37 | 'plugin:vue/base', 38 | 'plugin:vue/vue3-essential', 39 | 'plugin:vue/vue3-strongly-recommended', 40 | 'plugin:vue/vue3-recommended', 41 | ] 42 | .concat( 43 | isTsProject ? ['plugin:@typescript-eslint/recommended'] : [], 44 | ) 45 | .concat(['plugin:prettier/recommended']), 46 | parser: 'vue-eslint-parser', 47 | plugins: ['eslint-comments', 'jest', 'unicorn', 'filename'], 48 | env: { 49 | browser: true, 50 | node: true, 51 | es6: true, 52 | mocha: true, 53 | jest: true, 54 | jasmine: true, 55 | }, 56 | rules: { 57 | 'prettier/prettier': 'error', 58 | 'filename/match': [2, ['camelcase', 'pascalcase']], 59 | ...(isTsProject ? tsEslintConfig : {}), 60 | }, 61 | settings: { 62 | // support import modules from TypeScript files in JavaScript files 63 | 'import/resolver': { 64 | node: { 65 | extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.vue'], 66 | }, 67 | }, 68 | 'import/parsers': { 69 | '@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts', '.vue'], 70 | }, 71 | 'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts', '.vue'], 72 | 'import/external-module-folders': ['node_modules', 'node_modules/@types'], 73 | polyfills: ['fetch', 'Promise', 'URL', 'object-assign'], 74 | }, 75 | parserOptions: isTsProject ? Object.assign(parserOptions, { project: './tsconfig.json' }) : parserOptions, 76 | }; 77 | -------------------------------------------------------------------------------- /src/husky.ts: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | 3 | module.exports = { 4 | hooks: { 5 | 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', 6 | 'pre-commit': 'lint-staged', 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | 3 | const eslintReact = require('./eslintReact'); 4 | const eslintVue2 = require('./eslintVue2'); 5 | const eslintVue3 = require('./eslintVue3'); 6 | const eslintSvelte = require('./eslintSvelte'); 7 | const stylelint = require('./stylelint'); 8 | const prettier = require('./prettier'); 9 | const commitlint = require('./commitlint'); 10 | const husky = require('./husky'); 11 | const lintstaged = require('./lintstaged'); 12 | 13 | module.exports = { 14 | stylelint, 15 | prettier, 16 | eslintReact, 17 | eslintVue2, 18 | eslintVue3, 19 | eslintSvelte, 20 | commitlint, 21 | husky, 22 | lintstaged, 23 | }; 24 | -------------------------------------------------------------------------------- /src/lintstaged.ts: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | 3 | module.exports = { 4 | '*.{js,jsx,ts,tsx,vue,svelte}': ['eslint --fix', 'prettier --write'], 5 | '*.{less,postcss,css,scss,vue,svelte}': ['stylelint --fix', 'prettier --write'], 6 | }; 7 | -------------------------------------------------------------------------------- /src/prettier.ts: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | module.exports = { 3 | semi: true, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | bracketSpacing: true, 7 | jsxBracketSameLine: false, 8 | arrowParens: 'always', 9 | insertPragma: false, 10 | tabWidth: 2, 11 | useTabs: false, 12 | printWidth: 100, 13 | proseWrap: 'never', 14 | endOfLine: 'lf', 15 | overrides: [ 16 | { 17 | files: '.prettierrc', 18 | options: { 19 | parser: 'json', 20 | }, 21 | }, 22 | { 23 | files: 'document.ejs', 24 | options: { 25 | parser: 'html', 26 | }, 27 | }, 28 | ], 29 | "svelteSortOrder" : "options-styles-scripts-markup", 30 | "svelteStrictMode": true, 31 | "svelteBracketNewLine": false, 32 | "svelteAllowShorthand": false, 33 | "svelteIndentScriptAndStyle": false 34 | }; 35 | -------------------------------------------------------------------------------- /src/stylelint.ts: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /** @format */ 3 | module.exports = { 4 | extends: [ 5 | 'stylelint-config-standard', 6 | 'stylelint-config-css-modules', 7 | 'stylelint-config-rational-order', 8 | 'stylelint-config-prettier', 9 | 'stylelint-no-unsupported-browser-features', 10 | 'stylelint-prettier/recommended', 11 | ], 12 | plugins: ['stylelint-order', "stylelint-config-rational-order/plugin", "stylelint-scss", 'stylelint-declaration-block-no-ignored-properties'], 13 | rules: { 14 | // `standard` conflict with `rational-order` 15 | "declaration-empty-line-before": [ 16 | "never", 17 | { 18 | except: ['after-comment', 'after-declaration', 'first-nested'], 19 | ignore: [ 20 | "after-comment", 21 | "after-declaration", 22 | "first-nested", 23 | "inside-single-line-block", 24 | ], 25 | }, 26 | ], 27 | "order/properties-order": [], 28 | "plugin/rational-order": [true, { 29 | "border-in-box-model": false, 30 | "empty-line-between-groups": true, 31 | }], 32 | "at-rule-no-unknown": null, 33 | "scss/at-rule-no-unknown": true, 34 | "scss/comment-no-empty": true, 35 | "scss/at-if-no-null": true, 36 | "scss/at-function-parentheses-space-before": "never", 37 | "scss/at-mixin-parentheses-space-before": "never", 38 | "scss/at-import-no-partial-leading-underscore": true, 39 | "scss/dollar-variable-colon-space-after": "always", 40 | "scss/double-slash-comment-empty-line-before": [ 41 | "always", 42 | { 43 | "except": [ 44 | "first-nested" 45 | ], 46 | "ignore": [ 47 | "between-comments", 48 | "stylelint-commands" 49 | ] 50 | } 51 | ], 52 | "scss/no-duplicate-mixins": true, 53 | 54 | "selector-pseudo-class-no-unknown": [ 55 | true, 56 | { 57 | ignorePseudoClasses: ["global"], 58 | }, 59 | ], 60 | "no-empty-source": null, 61 | "unicode-bom": "never", 62 | "no-descending-specificity": null, 63 | "font-family-no-missing-generic-family-keyword": null, 64 | "declaration-colon-space-after": "always-single-line", 65 | "declaration-colon-space-before": "never", 66 | "rule-empty-line-before": [ 67 | "always", 68 | { 69 | ignore: ["after-comment", "first-nested"], 70 | }, 71 | ], 72 | //https://github.com/stylelint/stylelint/issues/4114 73 | "function-calc-no-invalid": null, 74 | "function-url-quotes": "always", 75 | "plugin/declaration-block-no-ignored-properties": true, 76 | "unit-no-unknown": [true, { ignoreUnits: ["rpx"] }], 77 | }, 78 | ignoreFiles: ["**/*.js", "**/*.jsx", "**/*.tsx", "**/*.ts"], 79 | }; 80 | -------------------------------------------------------------------------------- /src/tsEslintConfig.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | '@typescript-eslint/adjacent-overload-signatures': 0, 3 | '@typescript-eslint/array-type': 'error', 4 | '@typescript-eslint/await-thenable': 0, 5 | '@typescript-eslint/ban-ts-comment': 0, 6 | '@typescript-eslint/ban-tslint-comment': 0, 7 | 'brace-style': 'off', 8 | '@typescript-eslint/brace-style': 0, 9 | '@typescript-eslint/class-literal-property-style': 0, 10 | 'comma-dangle': 'off', 11 | '@typescript-eslint/comma-dangle': 0, 12 | 'comma-spacing': 'off', 13 | '@typescript-eslint/comma-spacing': 0, 14 | '@typescript-eslint/consistent-indexed-object-style': 1, 15 | '@typescript-eslint/consistent-type-assertions': 0, 16 | '@typescript-eslint/consistent-type-definitions': ['warn', 'type'], 17 | '@typescript-eslint/consistent-type-imports': 1, 18 | 'default-param-last': 'off', 19 | '@typescript-eslint/default-param-last': 0, 20 | 'dot-notation': 'off', 21 | '@typescript-eslint/dot-notation': 0, 22 | '@typescript-eslint/explicit-function-return-type': 0, 23 | 'func-call-spacing': 'off', 24 | '@typescript-eslint/func-call-spacing': 0, 25 | indent: 'off', 26 | 'init-declarations': 'off', 27 | '@typescript-eslint/init-declarations': 0, 28 | 'keyword-spacing': 'off', 29 | '@typescript-eslint/keyword-spacing': 0, 30 | 'lines-between-class-members': 'off', 31 | '@typescript-eslint/lines-between-class-members': 0, 32 | '@typescript-eslint/member-delimiter-style': 0, 33 | '@typescript-eslint/member-ordering': 0, 34 | '@typescript-eslint/method-signature-style': 'error', 35 | 'no-array-constructor': 'off', 36 | '@typescript-eslint/no-array-constructor': 0, 37 | '@typescript-eslint/no-base-to-string': 0, 38 | '@typescript-eslint/no-confusing-non-null-assertion': 'error', 39 | '@typescript-eslint/no-confusing-void-expression': 0, 40 | 'no-dupe-class-members': 'off', 41 | '@typescript-eslint/no-dupe-class-members': 'error', 42 | 'no-duplicate-imports': 'off', 43 | '@typescript-eslint/no-duplicate-imports': 0, 44 | '@typescript-eslint/no-dynamic-delete': 0, 45 | 'no-empty-function': 'off', 46 | '@typescript-eslint/no-empty-function': 0, 47 | '@typescript-eslint/no-empty-interface': 0, 48 | '@typescript-eslint/no-extra-non-null-assertion': 0, 49 | 'no-extra-parens': 'off', 50 | '@typescript-eslint/no-extra-parens': 0, 51 | 'no-extra-semi': 'off', 52 | '@typescript-eslint/no-extra-semi': 0, 53 | '@typescript-eslint/no-extraneous-class': 0, 54 | '@typescript-eslint/no-floating-promises': 0, 55 | '@typescript-eslint/no-for-in-array': 'error', 56 | '@typescript-eslint/no-implicit-any-catch': 0, 57 | 'no-implied-eval': 'off', 58 | '@typescript-eslint/no-implied-eval': 0, 59 | '@typescript-eslint/no-inferrable-types': 0, 60 | 'no-invalid-this': 'off', 61 | '@typescript-eslint/no-invalid-this': 'error', 62 | '@typescript-eslint/no-invalid-void-type': 0, 63 | 'no-loop-func': 'off', 64 | '@typescript-eslint/no-loop-func': 'error', 65 | 'no-loss-of-precision': 'off', 66 | '@typescript-eslint/no-loss-of-precision': 0, 67 | 'no-magic-numbers': 'off', 68 | '@typescript-eslint/no-magic-numbers': 0, 69 | '@typescript-eslint/no-misused-new': 'error', 70 | '@typescript-eslint/no-misused-promises': 0, 71 | '@typescript-eslint/no-namespace': 1, 72 | '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', 73 | '@typescript-eslint/no-parameter-properties': 'error', 74 | 'no-redeclare': 'off', 75 | '@typescript-eslint/no-redeclare': 'error', 76 | '@typescript-eslint/no-require-imports': 0, 77 | 'no-shadow': 'off', 78 | '@typescript-eslint/no-shadow': 'error', 79 | '@typescript-eslint/no-this-alias': 'error', 80 | 'no-throw-literal': 'off', 81 | '@typescript-eslint/no-throw-literal': 0, 82 | '@typescript-eslint/no-type-alias': 0, 83 | '@typescript-eslint/no-unnecessary-boolean-literal-compare': 0, 84 | '@typescript-eslint/no-unnecessary-condition': 0, 85 | '@typescript-eslint/no-unnecessary-qualifier': 0, 86 | '@typescript-eslint/no-unnecessary-type-arguments': 0, 87 | '@typescript-eslint/no-unnecessary-type-assertion': 0, 88 | '@typescript-eslint/no-unnecessary-type-constraint': 0, 89 | '@typescript-eslint/no-unsafe-assignment': 0, 90 | '@typescript-eslint/no-unsafe-call': 0, 91 | '@typescript-eslint/no-unsafe-member-access': 0, 92 | '@typescript-eslint/no-unsafe-return': 0, 93 | 'no-unused-expressions': 'off', 94 | '@typescript-eslint/no-unused-expressions': 'error', 95 | 'no-unused-vars': 'off', 96 | 'no-use-before-define': 'off', 97 | 'no-useless-constructor': 'off', 98 | '@typescript-eslint/no-useless-constructor': 'error', 99 | '@typescript-eslint/non-nullable-type-assertion-style': 0, 100 | '@typescript-eslint/prefer-as-const': 0, 101 | '@typescript-eslint/prefer-enum-initializers': 0, 102 | '@typescript-eslint/prefer-for-of': 0, 103 | '@typescript-eslint/prefer-function-type': 0, 104 | '@typescript-eslint/prefer-includes': 0, 105 | '@typescript-eslint/prefer-literal-enum-member': 0, 106 | '@typescript-eslint/prefer-namespace-keyword': 0, 107 | '@typescript-eslint/prefer-nullish-coalescing': 0, 108 | '@typescript-eslint/prefer-optional-chain': 0, 109 | '@typescript-eslint/prefer-readonly': 0, 110 | '@typescript-eslint/prefer-readonly-parameter-types': 0, 111 | '@typescript-eslint/prefer-reduce-type-parameter': 0, 112 | '@typescript-eslint/prefer-regexp-exec': 0, 113 | '@typescript-eslint/prefer-string-starts-ends-with': 0, 114 | '@typescript-eslint/prefer-ts-expect-error': 0, 115 | '@typescript-eslint/promise-function-async': 0, 116 | quotes: 'off', 117 | '@typescript-eslint/quotes': 0, 118 | '@typescript-eslint/require-array-sort-compare': 0, 119 | 'require-await': 'off', 120 | '@typescript-eslint/require-await': 0, 121 | '@typescript-eslint/restrict-plus-operands': 0, 122 | '@typescript-eslint/restrict-template-expressions': 0, 123 | 'no-return-await': 'off', 124 | '@typescript-eslint/return-await': 0, 125 | semi: 'off', 126 | '@typescript-eslint/semi': 0, 127 | 'space-before-function-paren': 'off', 128 | '@typescript-eslint/space-before-function-paren': 0, 129 | 'space-infix-ops': 'off', 130 | '@typescript-eslint/space-infix-ops': 0, 131 | '@typescript-eslint/strict-boolean-expressions': 0, 132 | '@typescript-eslint/switch-exhaustiveness-check': 0, 133 | '@typescript-eslint/triple-slash-reference': 'error', 134 | '@typescript-eslint/type-annotation-spacing': 'error', 135 | '@typescript-eslint/typedef': 'error', 136 | '@typescript-eslint/unbound-method': 0, 137 | '@typescript-eslint/unified-signatures': 'error', 138 | '@typescript-eslint/indent': 0, 139 | // Makes no sense to allow type inferrence for expression parameters, but require typing the response 140 | '@typescript-eslint/no-use-before-define': [ 141 | 'error', 142 | { functions: false, classes: true, variables: true, typedefs: true }, 143 | ], 144 | camelcase: 0, 145 | '@typescript-eslint/camelcase': 0, 146 | '@typescript-eslint/no-var-requires': 0, 147 | // Common abbreviations are known and readable 148 | '@typescript-eslint/explicit-member-accessibility': 0, 149 | '@typescript-eslint/interface-name-prefix': 0, 150 | '@typescript-eslint/no-non-null-assertion': 0, 151 | '@typescript-eslint/no-explicit-any': 0, 152 | '@typescript-eslint/ban-types': 1, 153 | '@typescript-eslint/explicit-module-boundary-types': 0, 154 | '@typescript-eslint/naming-convention': 0, 155 | '@typescript-eslint/no-unused-vars': [ 156 | 'error', 157 | { vars: 'all', args: 'after-used', ignoreRestSiblings: true }, 158 | ], 159 | }; 160 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "build/dist", 4 | "module": "esnext", 5 | "target": "esnext", 6 | "lib": ["esnext", "dom"], 7 | "sourceMap": true, 8 | "baseUrl": ".", 9 | "jsx": "react", 10 | "allowSyntheticDefaultImports": true, 11 | "moduleResolution": "node", 12 | "forceConsistentCasingInFileNames": true, 13 | "noImplicitReturns": true, 14 | "suppressImplicitAnyIndexErrors": true, 15 | "noUnusedLocals": true, 16 | "allowJs": true, 17 | "skipLibCheck": true, 18 | "experimentalDecorators": true, 19 | "strict": true, 20 | "paths": { 21 | "@/*": ["./src/*"] 22 | } 23 | }, 24 | "exclude": ["node_modules", "build", "dist", "scripts", "jest"] 25 | } 26 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "module": "commonjs", 5 | "target": "es5", 6 | "lib": ["esnext", "dom"], 7 | "baseUrl": ".", 8 | "jsx": "react", 9 | "resolveJsonModule": true, 10 | "allowSyntheticDefaultImports": true, 11 | "moduleResolution": "node", 12 | "forceConsistentCasingInFileNames": true, 13 | "noImplicitReturns": true, 14 | "suppressImplicitAnyIndexErrors": true, 15 | "noUnusedLocals": true, 16 | "experimentalDecorators": true, 17 | "strict": true, 18 | "skipLibCheck": true, 19 | "declaration": true 20 | }, 21 | "exclude": [ 22 | "node_modules", 23 | "build", 24 | "scripts", 25 | "acceptance-tests", 26 | "webpack", 27 | "jest", 28 | "dist", 29 | "src/setupTests.ts", 30 | "tslint:latest", 31 | "tslint-config-prettier", 32 | "example/**" 33 | ], 34 | "include": ["src/*.json", "src/*.ts"] 35 | } 36 | --------------------------------------------------------------------------------