From 2296aa81d54cab42fecc514d81d7dbbf0f7caaa2 Mon Sep 17 00:00:00 2001 From: David Worms Date: Sun, 29 Sep 2024 01:24:43 +0200 Subject: [PATCH] build: eslint and prettier --- .gitignore | 1 + .husky/commit-msg | 1 + .husky/pre-commit | 1 + .prettierrc.yml | 1 + commitlint.config.js | 10 ++++++++++ eslint.config.js | 18 ++++++++++++++++++ package.json | 34 ++++++++++++++++++++++++++-------- 7 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 .husky/commit-msg create mode 100644 .husky/pre-commit create mode 100644 .prettierrc.yml create mode 100644 commitlint.config.js create mode 100644 eslint.config.js diff --git a/.gitignore b/.gitignore index 0ee1a9f..df4db00 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ !.gitignore !.github !.husky +!.prettierrc.yml diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 0000000..fd2bf70 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npx --no-install commitlint --edit $1 diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..1fb913e --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npm run lint:staged diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000..7390111 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1 @@ +experimentalTernaries: true diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..7307ea0 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,10 @@ +export default { + extends: ["@commitlint/config-conventional"], + rules: { + "type-enum": [ + 2, + "always", + ["build", "chore", "ci", "docs", "feat", "fix", "refactor", "test"], + ], + }, +}; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..7ac3b00 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,18 @@ +import globals from "globals"; +import js from "@eslint/js"; +import ts from "typescript-eslint"; +import mocha from "eslint-plugin-mocha"; +import prettier from "eslint-plugin-prettier/recommended"; + +export default [ + { + ignores: ["dist/**"], + }, + { + languageOptions: { globals: { ...globals.node } }, + }, + js.configs.recommended, + ...ts.configs.recommended, + mocha.configs.flat.recommended, + prettier, +]; diff --git a/package.json b/package.json index c3eb4e7..4430c85 100644 --- a/package.json +++ b/package.json @@ -5,19 +5,31 @@ "author": "David Worms (https://www.adaltas.com)", "contributors": [], "devDependencies": { + "@commitlint/cli": "^19.5.0", + "@commitlint/config-conventional": "^19.5.0", + "@eslint/core": "^0.6.0", + "@eslint/js": "^9.11.1", + "@types/eslint__js": "^8.42.3", "@types/mocha": "^10.0.8", "@types/node": "^22.7.4", "@types/should": "^13.0.0", - "@types/wcwidth": "^1.0.2", "coffeescript": "^2.7.0", + "eslint": "^9.11.1", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-mocha": "^10.5.0", + "eslint-plugin-prettier": "^5.2.1", "husky": "^9.1.6", + "lint-staged": "^15.2.10", "mocha": "^10.7.3", + "prettier": "^3.3.3", "rollup": "^4.22.5", "rollup-plugin-commonjs": "^10.0.0", "rollup-plugin-node-resolve": "^5.0.0", "should": "^13.2.3", + "standard-version": "^9.5.0", "ts-node": "^10.9.2", - "typescript": "^5.6.2" + "typescript": "^5.6.2", + "typescript-eslint": "^8.7.0" }, "dependencies": { "wcwidth": "^1.0.1" @@ -34,6 +46,10 @@ "/dist" ], "license": "BSD-3-Clause", + "lint-staged": { + "*.js": "npm run lint:fix", + "*.md": "prettier -w" + }, "main": "dist/pad.cjs.js", "mocha": { "inline-diffs": true, @@ -53,12 +69,14 @@ }, "scripts": { "build": "rollup -c && cp -p lib/index.d.ts dist/pad.d.ts", - "preversion": "grep '## Trunk' CHANGELOG.md && npm test", - "version": "version=`grep '^ \"version\": ' package.json | sed 's/.*\"\\([0-9\\.]*\\)\".*/\\1/'` && sed -i \"s/## Trunk/## Version $version/\" CHANGELOG.md && git add CHANGELOG.md", - "postversion": "git push && git push --tags && npm publish", - "patch": "npm version patch -m 'Bump to version %s'", - "minor": "npm version minor -m 'Bump to version %s'", - "major": "npm version major -m 'Bump to version %s'", + "lint:check": "eslint", + "lint:fix": "eslint --fix", + "lint:staged": "npx lint-staged", + "release": "standard-version", + "release:minor": "standard-version --release-as minor", + "release:patch": "standard-version --release-as patch", + "release:major": "standard-version --release-as major", + "postrelease": "git push --follow-tags origin master", "test": "mocha test/*.{js,ts}", "prepare": "husky install" },