Skip to content

Commit

Permalink
feat(lint-staged): support custom ts config for lintstaged (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Jun 17, 2021
1 parent 32e596c commit 3a7c0af
Show file tree
Hide file tree
Showing 21 changed files with 2,365 additions and 1,004 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-plums-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@1stg/lint-staged": minor
---

feat(lint-staged): support custom ts config for lintstaged
5 changes: 5 additions & 0 deletions .changeset/metal-carrots-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@1stg/eslint-config": minor
---

feat(eslint-config): only enable eslint-plugin-sonar with typescript available
2 changes: 1 addition & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('@1stg/lint-staged')
module.exports = require('@1stg/lint-staged/tsc')
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,36 @@
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache -f friendly",
"lint:scss": "stylelint --cache 'tests/*.{scss,vue}'",
"lint:ts": "tslint -p . -t stylish",
"lint:tsc": "tsc",
"lint:tsc": "tsc --noEmit",
"postinstall": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"release": "changeset publish",
"test": "jest ---collectCoverage",
"typecov": "type-coverage"
},
"devDependencies": {
"@angular/compiler": "^12.0.3",
"@angular/core": "^12.0.3",
"@angular/compiler": "^12.0.5",
"@angular/core": "^12.0.5",
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@types/jest": "^26.0.23",
"@types/node": "^15.12.0",
"@types/react": "^17.0.9",
"@types/node": "^15.12.2",
"@types/react": "^17.0.11",
"@types/unist": "^2.0.3",
"core-js": "^3.13.1",
"postcss": "^8.3.0",
"core-js": "^3.14.0",
"postcss": "^8.3.5",
"react": "^17.0.2",
"rxjs": "^7.1.0",
"svelte": "^3.38.2",
"ts-jest": "^27.0.2",
"ts-jest": "^27.0.3",
"tslint": "^6.1.3",
"type-coverage": "^2.17.5",
"typescript": "^4.3.2",
"vue": "^2.6.13"
"typescript": "^4.3.3",
"vue": "^2.6.14",
"vue-tsc": "^0.1.7"
},
"resolutions": {
"@babel/core": "^7.14.3",
"prettier": "^2.3.0"
"@babel/core": "^7.14.6",
"prettier": "^2.3.1"
},
"typeCoverage": {
"atLeast": 100,
Expand Down
2 changes: 1 addition & 1 deletion packages/app-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@pkgr/es-modules": "^0.4.2",
"@pkgr/imagemin": "^1.0.1",
"browserslist": "^4.16.6",
"postcss": "^8.3.0",
"postcss": "^8.3.5",
"stylelint": "^13.13.1"
},
"publishConfig": {
Expand Down
16 changes: 8 additions & 8 deletions packages/babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"@babel/core": ">=7.14.1"
},
"dependencies": {
"@babel/helper-plugin-utils": "^7.13.0",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-decorators": "^7.14.2",
"@babel/preset-env": "^7.14.4",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"@babel/helper-plugin-utils": "^7.14.5",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-decorators": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@pkgr/utils": "^1.0.1",
"@vue/babel-helper-vue-jsx-merge-props": "^1.2.1",
"@vue/babel-plugin-jsx": "^1.0.6",
Expand All @@ -27,8 +27,8 @@
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"babel-plugin-transform-remove-console": "^6.9.4",
"babel-plugin-transform-typescript-metadata": "^0.3.2",
"babel-preset-proposal-typescript": "^2.1.0",
"core-js": "^3.13.1",
"babel-preset-proposal-typescript": "^2.2.0",
"core-js": "^3.14.0",
"fast-async": "^7.0.6"
},
"publishConfig": {
Expand Down
8 changes: 4 additions & 4 deletions packages/common-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
"@1stg/remark-config": "^1.1.0",
"@1stg/simple-git-hooks": "^0.1.2",
"@1stg/tsconfig": "^1.3.1",
"@babel/core": "^7.14.3",
"@babel/core": "^7.14.6",
"@commitlint/cli": "^12.1.4",
"eslint": "^7.27.0",
"eslint": "^7.28.0",
"lint-staged": "^11.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.0",
"prettier": "^2.3.1",
"simple-git-hooks": "^2.4.1",
"tslib": "^2.2.0",
"tslib": "^2.3.0",
"yarn-deduplicate": "^3.1.0"
},
"publishConfig": {
Expand Down
7 changes: 4 additions & 3 deletions packages/eslint-config/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { isTsAvailable } = require('@pkgr/utils')
const { getGlobals } = require('eslint-plugin-mdx')

const { isWebpackAvailable, magicNumbers, webpackSpecVars } = require('./_util')
Expand All @@ -10,11 +11,11 @@ module.exports = {
'plugin:node/recommended',
'plugin:promise/recommended',
'plugin:sonarjs/recommended',
'plugin:sonar/recommended',
isTsAvailable && 'plugin:sonar/recommended',
'plugin:unicorn/recommended',
'standard',
'plugin:prettier/recommended',
],
].filter(Boolean),
globals: isWebpackAvailable ? getGlobals(webpackSpecVars) : undefined,
rules: {
'arrow-body-style': 2,
Expand Down Expand Up @@ -53,7 +54,7 @@ module.exports = {
},
],
'no-empty-function': 2,
'no-labels': 0, // sonar/no-labels
'no-labels': isTsAvailable ? 2 : 0, // sonar/no-labels
'no-magic-numbers': [
2,
{
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-config/overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ exports.react = [
eventHandlerPropPrefix: 'on',
},
],
'sonar/function-name': [2, { format: '^_?[a-zA-Z][a-zA-Z0-9]*\\$?$' }],
'sonar/function-name': isTsAvailable
? [2, { format: '^_?[a-zA-Z][a-zA-Z0-9]*\\$?$' }]
: 0,
},
...reactJsx,
},
Expand Down
18 changes: 9 additions & 9 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"@angular-eslint/eslint-plugin": "^12.1.0",
"@angular-eslint/eslint-plugin-template": "^12.1.0",
"@angular-eslint/template-parser": "^12.1.0",
"@babel/eslint-parser": "^7.14.4",
"@babel/eslint-plugin": "^7.13.16",
"@babel/eslint-parser": "^7.14.5",
"@babel/eslint-plugin": "^7.14.5",
"@pkgr/utils": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"angular-eslint-template-parser": "^0.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
Expand All @@ -32,18 +32,18 @@
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-jsdoc": "^35.3.0",
"eslint-plugin-mdx": "^1.13.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-sonar": "^0.5.1",
"eslint-plugin-sonarjs": "^0.7.1-117",
"eslint-plugin-sonar": "^0.6.0",
"eslint-plugin-sonarjs": "^0.8.0-125",
"eslint-plugin-svelte": "^1.1.2",
"eslint-plugin-unicorn": "^33.0.1",
"eslint-plugin-vue": "^7.10.0"
"eslint-plugin-vue": "^7.11.1"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@1stg/common-config": "^2.2.0",
"@pkgr/rollup": "^1.0.2",
"@pkgr/rollup": "^1.1.4",
"jest": "^27.0.4"
},
"publishConfig": {
Expand Down
9 changes: 9 additions & 0 deletions packages/lint-staged/_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require('path')

const { tryFile, tryPkg } = require('@pkgr/utils')

exports.tsConfig =
tryFile(path.resolve('tsconfig.staged.json')) ||
tryFile(path.resolve('tsconfig.base.json')) ||
tryFile(path.resolve('tsconfig.json')) ||
tryPkg('@1stg/tsconfig')
2 changes: 1 addition & 1 deletion packages/lint-staged/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { isPkgAvailable, tryFile } = require('@pkgr/utils')

const config = [
'*.{*sh,env,env.*,gql,html,json,properties,pug,rb,svelte,vue,toml,yaml,yml}',
'.(editorconfig|*rc)',
'.*rc',
'Dockerfile',
].reduce(
(acc, files) =>
Expand Down
4 changes: 3 additions & 1 deletion packages/lint-staged/ngc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { tsConfig } = require('./_utils')

module.exports = {
...require('./base'),
'*.{html,ts}': () => 'ngc --noEmit',
'*.{html,ts}': () => `ngc -p ${tsConfig} --noEmit`,
}
3 changes: 2 additions & 1 deletion packages/lint-staged/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
},
"dependencies": {
"@1stg/prettier-config": "^1.7.3",
"@1stg/tsconfig": "^1.4.0",
"@pkgr/utils": "^1.0.1",
"cross-env": "^7.0.3",
"prettier": "^2.3.0"
"prettier": "^2.3.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 3 additions & 1 deletion packages/lint-staged/tsc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { tsConfig } = require('./_utils')

module.exports = {
...require('./base'),
'*.ts?(x)': () => 'tsc --noEmit',
'*.ts?(x)': () => `tsc -p ${tsConfig} --noEmit`,
}
6 changes: 6 additions & 0 deletions packages/lint-staged/vue-tsc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { tsConfig } = require('./_utils')

module.exports = {
...require('./base'),
'*.{vue,ts,tsx}': () => `vue-tsc -p ${tsConfig} --noEmit --incremental false`,
}
6 changes: 3 additions & 3 deletions packages/postcss-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
},
"dependencies": {
"autoprefixer": "^10.2.6",
"cssnano": "^5.0.5",
"cssnano-preset-advanced": "^5.1.2",
"cssnano": "^5.0.6",
"cssnano-preset-advanced": "^5.1.3",
"postcss-import": "^14.0.2",
"postcss-modules": "^4.1.0",
"postcss-modules": "^4.1.3",
"postcss-normalize": "^10.0.0",
"postcss-preset-env": "^6.7.0",
"postcss-url": "^10.1.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"prettier": ">=1.18.0"
},
"dependencies": {
"@prettier/plugin-pug": "^1.15.2",
"@prettier/plugin-pug": "^1.15.3",
"@prettier/plugin-ruby": "^1.5.5",
"@prettier/plugin-xml": "^0.13.1",
"prettier-plugin-pkg": "^0.9.0",
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "./packages/tsconfig/tsconfig.json",
"extends": "./packages/tsconfig/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"lib": ["DOM"],
"noEmit": true
"lib": ["DOM"]
},
"exclude": ["node_modules"]
}
Loading

0 comments on commit 3a7c0af

Please sign in to comment.