From 83a7dd7ea18996f1cc0d6a2fc494fd27dd8affd3 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 22 Nov 2022 16:58:59 +0100 Subject: [PATCH] chore: remove custom scripts/lint-staged --- .husky/pre-commit | 2 +- package.json | 7 ++++- scripts/lint-staged.js | 68 ------------------------------------------ 3 files changed, 7 insertions(+), 70 deletions(-) delete mode 100755 scripts/lint-staged.js diff --git a/.husky/pre-commit b/.husky/pre-commit index 34f0a10273..d24fdfc601 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx lint-staged && scripts/lint-staged.js +npx lint-staged diff --git a/package.json b/package.json index 3b824380f4..dd15222649 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,12 @@ "testRegex": "\\.spec\\.js$" }, "lint-staged": { - "*.{md,ts,ts}": "prettier --write" + "*.{{,c,m}j,t}s{,x}": [ + "prettier --write", + "eslint --ignore-pattern '!*'", + "jest --testRegex='^(?!.*.integ.spec.js$).*.spec.js$' --findRelatedTests --passWithNoTests" + ], + "*.md": "prettier --write" }, "private": true, "scripts": { diff --git a/scripts/lint-staged.js b/scripts/lint-staged.js deleted file mode 100755 index 553ee1fda2..0000000000 --- a/scripts/lint-staged.js +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env node - -'use strict' - -const formatFiles = files => { - run('./node_modules/.bin/prettier', ['--write'].concat(files)) -} -const testFiles = files => { - run('./node_modules/.bin/eslint', ['--ignore-pattern', '!*'].concat(files)) - run( - './node_modules/.bin/jest', - ['--testRegex=^(?!.*.integ.spec.js$).*.spec.js$', '--findRelatedTests', '--passWithNoTests'].concat(files) - ) -} - -// ----------------------------------------------------------------------------- - -const { execFileSync, spawnSync } = require('child_process') -const { readFileSync, writeFileSync } = require('fs') - -const run = (command, args) => { - const { status } = spawnSync(command, args, { stdio: 'inherit' }) - if (status !== 0) { - process.exit(status) - } -} - -const gitDiff = (what, args = []) => - execFileSync('git', ['diff-' + what, '--diff-filter=AM', '--ignore-submodules', '--name-only'].concat(args), { - encoding: 'utf8', - }) - .split('\n') - .filter(_ => _ !== '') -const gitDiffFiles = (files = []) => gitDiff('files', files) -const gitDiffIndex = () => gitDiff('index', ['--cached', 'HEAD']) - -// ----------------------------------------------------------------------------- - -const files = gitDiffIndex().filter(_ => _.endsWith('.cjs') || _.endsWith('.js') || _.endsWith('.mjs')) -if (files.length === 0) { - return -} - -// save the list of files with unstaged changes -let unstaged = gitDiffFiles(files) - -// format all files -formatFiles(files) - -if (unstaged.length !== 0) { - // refresh the list of files with unstaged changes, maybe the - // changes have been reverted by the formatting - run('git', ['update-index', '-q', '--refresh']) - unstaged = gitDiffFiles(unstaged) - - if (unstaged.length !== 0) { - const contents = unstaged.map(name => readFileSync(name)) - process.on('exit', () => unstaged.map((name, i) => writeFileSync(name, contents[i]))) - run('git', ['checkout'].concat(unstaged)) - formatFiles(unstaged) - } -} - -// add formatting changes so that even if the test fails, there won't be -// stylistic diffs between files and index -run('git', ['add'].concat(files)) - -testFiles(files)