Skip to content

Commit

Permalink
feat: update dotfiles, improve lint-staged config
Browse files Browse the repository at this point in the history
lint-staged now runs prettier on all supported files instead on only predefined file types, see https://maier.tech/posts/optimizing-lint-staged-config-js-for-prettier for more information.
  • Loading branch information
marcopixel committed Jun 25, 2021
1 parent 6c84917 commit 3f67e1b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 191 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
15 changes: 9 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:promise/recommended",
"plugin:unicorn/recommended"
]
"plugin:unicorn/recommended",
"prettier"
],
"rules": {
"unicorn/prefer-node-protocol": "off",
"unicorn/prefer-module": "off",
"unicorn/prevent-abbreviations": "off"
}
}
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,3 @@ $RECYCLE.BIN/
*.lnk

# End of https://www.gitignore.io/api/node,windows,visualstudiocode

### r6operators ###
src/icons.json
lib
158 changes: 0 additions & 158 deletions .prettierignore

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"semi": false,
"arrowParens": "always",
"singleQuote": false,
"tabWidth": 2,
"printWidth": 100
}
43 changes: 43 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable unicorn/prefer-array-flat-map */

// Source: https://coding.maier.tech/posts/optimizing-lint-staged-config-js-for-prettier/

const micromatch = require("micromatch")
const prettier = require("prettier")

// Figure out all extensions supported by Prettier.
const prettierSupportedExtensions = prettier
.getSupportInfo()
.languages.map(({ extensions }) => extensions)
.flat()

const addQuotes = (a) => `"${a}"`

module.exports = (allStagedFiles) => {
// Match files for ESLint
const eslintFiles = micromatch(allStagedFiles, ["**/*.{js,ts}"], {
dot: true,
})

// Match files for Prettier
const prettierFiles = micromatch(
allStagedFiles,
prettierSupportedExtensions.map((extension) => `**/*${extension}`),
{ dot: true }
)

// Array of linters to be run in this sequence.
const linters = []

// Add linters only when there are staged files for them.
// 'prettier --write' causes lint-staged to never terminate when prettierFiles is empty.

if (eslintFiles.length > 0) linters.push(`eslint --fix ${eslintFiles.join(" ")}`)

if (prettierFiles.length > 0)
linters.push(`prettier --write ${prettierFiles.map((element) => addQuotes(element)).join(" ")}`)

return linters
}
33 changes: 11 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r6operators",
"version": "1.6.0",
"version": "2.0.0",
"description": "r6operators is a collection of high-quality vectorized Rainbow Six: Siege Operator icons & metadata for Node.js",
"keywords": [
"rainbow six siege",
Expand All @@ -19,7 +19,7 @@
"url": "https://github.com/marcopixel/r6operators.git"
},
"license": "MIT",
"author": "Marco Vockner <[email protected]>",
"author": "Marco Vockner <[email protected]>",
"contributors": [
"dtSniper (https://twitter.com/sniperdt)",
"Joey Foo (https://github.com/joeyfoo)",
Expand All @@ -37,7 +37,7 @@
"build:ts": "tsc",
"clean": "npx rimraf lib src/icons.json",
"lint": "eslint **/*.{js,ts} --ignore-path .gitignore",
"format": "prettier **/* --check --write",
"format": "prettier **/* --ignore-path .gitignore --check --write",
"test": "jest",
"type-check": "tsc --noEmit",
"prepare": "husky install"
Expand All @@ -48,28 +48,17 @@
"npm-run-all": "^4.1.5"
},
"devDependencies": {
"@types/cheerio": "^0.22.24",
"@types/jest": "^26.0.20",
"@types/node": "^15.6.1",
"@types/sharp": "^0.28.2",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "^7.21.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-unicorn": "^32.0.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"esbuild": "^0.12.2",
"eslint": "^7.28.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-unicorn": "^33.0.1",
"husky": "^6.0.0",
"jest": "^27.0.2",
"lint-staged": "^11.0.0",
"prettier": "^2.2.1",
"sharp": "^0.28.3",
"svgo": "^2.2.1",
"ts-jest": "^27.0.1",
"prettier": "^2.3.0",
"ts-node": "^10.0.0",
"typescript": "^4.2.3"
},
"lint-staged": {
"*.{js,ts}": "eslint --cache --fix",
"*.--write": "prettier --write"
"typescript": "^4.3.2"
}
}

0 comments on commit 3f67e1b

Please sign in to comment.