From cb05ac17ab65aa060f4461c6d8e18170c67881cc Mon Sep 17 00:00:00 2001 From: Kieran Hall Date: Fri, 1 Mar 2024 14:22:34 +0100 Subject: [PATCH] Add eslint-plugin-import-newlines Resolves #12 --- README.md | 16 ++++++++++------ js/import-newlines.js | 5 +++++ js/index.js | 5 ++++- package.json | 22 +++++++++++++--------- 4 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 js/import-newlines.js diff --git a/README.md b/README.md index bc5ff91..568569d 100644 --- a/README.md +++ b/README.md @@ -10,18 +10,20 @@ npm i -D @dusk-network/eslint-config The package requires the following peer dependencies: -- [`eslint`](https://github.com/eslint/eslint) `>=8` -- [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) `>=2` +- [`eslint`](https://github.com/eslint/eslint) `>=8.57.0` +- [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) `>=9.1.0` +- [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) `>=2.29.1` +- [`eslint-plugin-import-newlines`](https://github.com/SeinopSys/eslint-plugin-import-newlines) `>=1.3.4` -If you are using Svelte rules the package need the following optional dependency: +If you are using Svelte rules the package needs the following optional dependency: -- [`eslint-plugin-svelte`](https://github.com/sveltejs/eslint-plugin-svelte) `>=2` +- [`eslint-plugin-svelte`](https://github.com/sveltejs/eslint-plugin-svelte) `>=2.35.1` ## Usage Add the rulesets you want in the `extends` section of your ESLint configuration file. -e.g. to use both JS and Svelte's rules: +e.g. to use both JS and Svelte rules: ```javascript // ... @@ -36,9 +38,11 @@ extends: [ # npm scripts -- `npm run bump` updates version number using an interactive shell - `npm run check` checks for deprecated rules and performs the linting check - `npm run check-js` checks for deprecated JS rules - `npm run check-rules` checks for deprecated JS and Svelte rules - `npm run check-svelte` checks for deprecated Svelte rules +- `npm run format` performs the Prettier formatting check +- `npm run format:fix` reformats according to the Prettier rules - `npm run lint` performs the linting check +- `npm run lint:fix` fixes fixable linting errors diff --git a/js/import-newlines.js b/js/import-newlines.js new file mode 100644 index 0000000..c29ede9 --- /dev/null +++ b/js/import-newlines.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + "import-newlines/enforce": "error", + }, +}; diff --git a/js/index.js b/js/index.js index a8c69e8..cc21f1f 100644 --- a/js/index.js +++ b/js/index.js @@ -1,4 +1,6 @@ -const rules = ["./base", "./import", "./style"].map(require.resolve); +const rules = ["./base", "./import", "./import-newlines", "./style"].map( + require.resolve +); module.exports = { extends: [ @@ -12,5 +14,6 @@ module.exports = { ecmaVersion: "latest", sourceType: "module", }, + plugins: ["import-newlines"], rules: {}, }; diff --git a/package.json b/package.json index 36c02db..74e30ff 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "url": "https://dusk.network/", "mail": "info@dusk.network" }, - "bugs": "https://github.com/dusk-network/dusk-eslint-config/issues/", + "bugs": "https://github.com/dusk-network/eslint-config/issues/", "contributors": [ "Andrea Scartabelli ", "Kieran Hall " @@ -17,7 +17,7 @@ "js/**/*.js", "svelte/**/*.js" ], - "homepage": "https://github.com/dusk-network/dusk-eslint-config/", + "homepage": "https://github.com/dusk-network/eslint-config/", "keywords": [ "dusk", "dusk network", @@ -28,33 +28,37 @@ "name": "@dusk-network/eslint-config", "repository": { "type": "git", - "url": "https://github.com/dusk-network/dusk-eslint-config.git" + "url": "https://github.com/dusk-network/eslint-config.git" }, "scripts": { "check": "npm run check-rules && npm run check-format && npm run lint", - "check-format": "prettier . --check", + "format": "prettier . --check", + "format:fix": "prettier . --write", "check-js": "eslint-find-rules -nd js/index.js && eslint-config-prettier js/index.js", "check-rules": "npm run check-js && npm run check-svelte", "check-svelte": "eslint-find-rules -nd svelte/index.js && eslint-config-prettier svelte/index.js", - "lint": "eslint ." + "lint": "eslint .", + "lint:fix": "eslint . --fix" }, "version": "3.1.0", "devDependencies": { "@dusk-network/prettier-config": "1.0.0", - "eslint": "8.56.0", + "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "eslint-find-rules": "4.1.0", "eslint-plugin-import": "2.29.1", + "eslint-plugin-import-newlines": "1.3.4", "eslint-plugin-svelte": "2.35.1", "prettier": "3.2.5", - "svelte": "4.2.10" + "svelte": "4.2.12" }, "optionalDependencies": { "eslint-plugin-svelte": ">=2.35.1" }, "peerDependencies": { - "eslint": ">=8.56.0", + "eslint": ">=8.57.0", "eslint-config-prettier": ">=9.1.0", - "eslint-plugin-import": ">=2.29.1" + "eslint-plugin-import": ">=2.29.1", + "eslint-plugin-import-newlines": ">=1.3.4" } }