Skip to content

Commit

Permalink
fix: lint-staged config (#55)
Browse files Browse the repository at this point in the history
* fix: lint-staged config

* fix: lint-staged config

* fix: lint-staged config

* fix: lint-staged config

* fix: lint-staged config

* chore: changeset

* chore: update lockfile
  • Loading branch information
lotyp authored Feb 23, 2023
1 parent ffda9fc commit 72695a5
Show file tree
Hide file tree
Showing 32 changed files with 245 additions and 226 deletions.
14 changes: 14 additions & 0 deletions .changeset/twenty-bags-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@wayofdev/browserslist-config': patch
'@wayofdev/eslint-config-bases': patch
'@wayofdev/markdownlint-config': patch
'@wayofdev/lint-staged-config': patch
'@wayofdev/commitlint-config': patch
'@wayofdev/secretlint-config': patch
'@wayofdev/stylelint-config': patch
'@wayofdev/htmlhint-config': patch
'@wayofdev/tsconfig-config': patch
'@wayofdev/postcss-config': patch
---

fix: lint-staged config changes
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { getDefaultIgnorePatterns } = require('@wayofdev/eslint-config-bases/helpers')

module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.base.json',
},
ignorePatterns: [...getDefaultIgnorePatterns()],
extends: [
'@wayofdev/eslint-config-bases/typescript',
'@wayofdev/eslint-config-bases/mdx',
'@wayofdev/eslint-config-bases/prettier-plugin',
],
}
21 changes: 10 additions & 11 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// @ts-check

const {
concatFilesForPrettier,
jsonRules,
secretsRules,
mdRules,
yamlRules,
} = require('@wayofdev/lint-staged-config')
const { concatFilesForPrettier } = require('@wayofdev/lint-staged-config')

const json = require('@wayofdev/lint-staged-config/json')
const yaml = require('@wayofdev/lint-staged-config/yaml')
const secrets = require('@wayofdev/lint-staged-config/secrets')
const md = require('@wayofdev/lint-staged-config/md')

const rules = {
...jsonRules,
...yamlRules,
...secretsRules,
...mdRules,
...json,
...yaml,
...secrets,
...md,
'**/*.{js,jsx,cjs,mjs,ts,tsx,mts,cts}': filenames => {
return [`prettier --write ${concatFilesForPrettier(filenames)}`]
},
Expand Down
27 changes: 13 additions & 14 deletions packages/browserslist-config/lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
* {@link https://github.com/belgattitude/nextjs-monorepo-example/blob/main/docs/about-lint-staged.md}
*/

const {
getEslintFixCmd,
jsonRules,
secretsRules,
mdRules,
yamlRules,
htmlRules,
} = require('@wayofdev/lint-staged-config')
const { getEslintFixCmd } = require('@wayofdev/lint-staged-config')

const json = require('@wayofdev/lint-staged-config/json')
const yaml = require('@wayofdev/lint-staged-config/yaml')
const secrets = require('@wayofdev/lint-staged-config/secrets')
const md = require('@wayofdev/lint-staged-config/md')
const html = require('@wayofdev/lint-staged-config/html')

/**
* @typedef {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>} LintRule
*/
const rules = {
'**/*.{js,jsx,ts,tsx}': (/** @type {any} */ filenames) => {
...json,
...secrets,
...md,
...yaml,
...html,
'**/*.{js,jsx,ts,tsx}': filenames => {
return getEslintFixCmd({
cwd: __dirname,
fix: true,
Expand All @@ -32,11 +36,6 @@ const rules = {
files: filenames,
})
},
...jsonRules,
...secretsRules,
...mdRules,
...yamlRules,
...htmlRules,
}

module.exports = rules
3 changes: 2 additions & 1 deletion packages/browserslist-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"browserslist": "^4.21.5"
},
"devDependencies": {
"rimraf": "^4.1.2"
"rimraf": "^4.1.2",
"@wayofdev/lint-staged-config": "workspace:*"
},
"publishConfig": {
"access": "public"
Expand Down
25 changes: 12 additions & 13 deletions packages/commitlint-config/lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
* {@link https://github.com/belgattitude/nextjs-monorepo-example/blob/main/docs/about-lint-staged.md}
*/

const {
getEslintFixCmd,
jsonRules,
secretsRules,
mdRules,
yamlRules,
htmlRules,
} = require('@wayofdev/lint-staged-config')
const { getEslintFixCmd } = require('@wayofdev/lint-staged-config')

const json = require('@wayofdev/lint-staged-config/json')
const yaml = require('@wayofdev/lint-staged-config/yaml')
const secrets = require('@wayofdev/lint-staged-config/secrets')
const md = require('@wayofdev/lint-staged-config/md')
const html = require('@wayofdev/lint-staged-config/html')

/**
* @typedef {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>} LintRule
Expand All @@ -32,11 +31,11 @@ const rules = {
files: filenames,
})
},
...jsonRules,
...secretsRules,
...mdRules,
...yamlRules,
...htmlRules,
...json,
...secrets,
...md,
...yaml,
...html,
}

module.exports = rules
3 changes: 2 additions & 1 deletion packages/commitlint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
},
"devDependencies": {
"es-check": "^7.1.0",
"rimraf": "^4.1.2"
"rimraf": "^4.1.2",
"@wayofdev/lint-staged-config": "workspace:*"
},
"peerDependencies": {
"@commitlint/cli": ">= 17"
Expand Down
25 changes: 12 additions & 13 deletions packages/eslint-config-bases/lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
* {@link https://github.com/belgattitude/nextjs-monorepo-example/blob/main/docs/about-lint-staged.md}
*/

const {
getEslintFixCmd,
jsonRules,
secretsRules,
mdRules,
yamlRules,
htmlRules,
} = require('@wayofdev/lint-staged-config')
const { getEslintFixCmd } = require('@wayofdev/lint-staged-config')

const json = require('@wayofdev/lint-staged-config/json')
const yaml = require('@wayofdev/lint-staged-config/yaml')
const secrets = require('@wayofdev/lint-staged-config/secrets')
const md = require('@wayofdev/lint-staged-config/md')
const html = require('@wayofdev/lint-staged-config/html')

/**
* @typedef {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>} LintRule
Expand All @@ -32,11 +31,11 @@ const rules = {
files: filenames,
})
},
...jsonRules,
...secretsRules,
...mdRules,
...yamlRules,
...htmlRules,
...json,
...secrets,
...md,
...yaml,
...html,
}

module.exports = rules
25 changes: 12 additions & 13 deletions packages/htmlhint-config/lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
* {@link https://github.com/belgattitude/nextjs-monorepo-example/blob/main/docs/about-lint-staged.md}
*/

const {
getEslintFixCmd,
jsonRules,
secretsRules,
mdRules,
yamlRules,
htmlRules,
} = require('@wayofdev/lint-staged-config')
const { getEslintFixCmd } = require('@wayofdev/lint-staged-config')

const json = require('@wayofdev/lint-staged-config/json')
const yaml = require('@wayofdev/lint-staged-config/yaml')
const secrets = require('@wayofdev/lint-staged-config/secrets')
const md = require('@wayofdev/lint-staged-config/md')
const html = require('@wayofdev/lint-staged-config/html')

/**
* @typedef {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>} LintRule
Expand All @@ -32,11 +31,11 @@ const rules = {
files: filenames,
})
},
...jsonRules,
...secretsRules,
...mdRules,
...yamlRules,
...htmlRules,
...json,
...secrets,
...md,
...yaml,
...html,
}

module.exports = rules
3 changes: 2 additions & 1 deletion packages/htmlhint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"lint:types": "tsc --project tsconfig.json --noEmit"
},
"devDependencies": {
"rimraf": "^4.1.2"
"rimraf": "^4.1.2",
"@wayofdev/lint-staged-config": "workspace:*"
},
"peerDependencies": {
"htmlhint": ">= 1"
Expand Down
66 changes: 30 additions & 36 deletions packages/lint-staged-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,68 +69,62 @@ This package should be installed in the root of your mono-repository, where you
1. Create `lint-staged.config.js` file in root of mono-repository and add lines:

```javascript
// @ts-check

const {
concatFilesForPrettier,
jsonRules,
secretsRules,
mdRules,
yamlRules,
} = require('@wayofdev/lint-staged-config')

const { concatFilesForPrettier } = require("@wayofdev/lint-staged-config")

const json = require("@wayofdev/lint-staged-config/json")
const yaml = require("@wayofdev/lint-staged-config/yaml")
const secrets = require("@wayofdev/lint-staged-config/secrets")
const md = require("@wayofdev/lint-staged-config/md")

const rules = {
...jsonRules,
...yamlRules,
...secretsRules,
...mdRules,
'**/*.{js,jsx,cjs,mjs,ts,tsx,mts,cts}': filenames => {
...json,
...yaml,
...secrets,
...md,
"**/*.{js,jsx,cjs,mjs,ts,tsx,mts,cts}": filenames => {
return [`prettier --write ${concatFilesForPrettier(filenames)}`]
},
}

module.exports = rules
```

2. If needed, override the base `lint-staged.config.js` in each package or application.

Example `lint-staged.config.js` in folder `./packages/eslint-config-bases/`

```typescript
// @ts-check

const {
getEslintFixCmd,
jsonRules,
secretsRules,
mdRules,
yamlRules,
htmlRules,
} = require('@wayofdev/lint-staged-config')

const { getEslintFixCmd } = require("@wayofdev/lint-staged-config")

const json = require("@wayofdev/lint-staged-config/json")
const yaml = require("@wayofdev/lint-staged-config/yaml")
const secrets = require("@wayofdev/lint-staged-config/secrets")
const md = require("@wayofdev/lint-staged-config/md")
const html = require("@wayofdev/lint-staged-config/html")

/**
* @typedef {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>} LintRule
*/
const rules = {
'**/*.{js,jsx,ts,tsx}': (/** @type {any} */ filenames) => {
"**/*.{js,jsx,ts,tsx}": (/** @type {any} */ filenames) => {
return getEslintFixCmd({
cwd: __dirname,
fix: true,
cache: true,
// when autofixing staged-files a good tip is to disable react-hooks/exhaustive-deps, cause
// a change here can potentially break things without proper visibility.
rules: ['react-hooks/exhaustive-deps: off'],
rules: ["react-hooks/exhaustive-deps: off"],
maxWarnings: 25,
files: filenames,
})
},
...jsonRules,
...secretsRules,
...mdRules,
...yamlRules,
...htmlRules,
...json,
...secrets,
...md,
...yaml,
...html,
}

module.exports = rules
```

Expand Down
6 changes: 6 additions & 0 deletions packages/lint-staged-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
".": {
"require": "./src/common.js"
},
"./helpers": {
"require": "./src/common.js"
},
"./bases": {
"require": "./src/bases/index.js"
},
"./css": {
"require": "./src/bases/css.js"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/lint-staged-config/src/bases/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ const { concatFilesForPrettier } = require('../common')
/**
* @type {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>}
*/
const rules = {
module.exports = {
'**/*.{css}': filenames => {
return [`prettier --write ${concatFilesForPrettier(filenames)}`, `stylelint --fix`]
},
}

module.exports = rules
4 changes: 1 addition & 3 deletions packages/lint-staged-config/src/bases/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ const { concatFilesForPrettier } = require('../common')
/**
* @type {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>}
*/
const rules = {
module.exports = {
'**/*.{gql,graphql}': filenames => {
return [`prettier --write ${concatFilesForPrettier(filenames)}`]
},
}

module.exports = rules
Loading

0 comments on commit 72695a5

Please sign in to comment.