diff --git a/.eslintignore b/.eslintignore index 0f8b6ec..3f593a7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ !/.* +/build/ /test-config/ diff --git a/.eslintrc.base.js b/.eslintrc.base.js index e3697df..7881467 100644 --- a/.eslintrc.base.js +++ b/.eslintrc.base.js @@ -1,6 +1,6 @@ "use strict"; -const pkg = require("./package.json"); +const fs = require("fs"); module.exports = { extends: [ @@ -12,8 +12,12 @@ module.exports = { ], plugins: [ "prettier", - ...pkg.files - .filter((name) => !name.includes("/") && name !== "index.js") + ...fs + .readdirSync(__dirname) + .filter( + (file) => + !file.startsWith(".") && file.endsWith(".js") && file !== "index.js" + ) .map((ruleFileName) => ruleFileName.replace(/\.js$/, "")), ], parserOptions: { diff --git a/.eslintrc.js b/.eslintrc.js index 63b3059..2bbbc12 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,12 +1,13 @@ "use strict"; -const pkg = require("./package.json"); +const fs = require("fs"); module.exports = { extends: [ "./.eslintrc.base.js", - ...pkg.files - .filter((name) => !name.includes("/")) + ...fs + .readdirSync(__dirname) + .filter((file) => !file.startsWith(".") && file.endsWith(".js")) .map((ruleFileName) => `./${ruleFileName}`), ], rules: { diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 47f3602..3bacd41 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -38,3 +38,6 @@ jobs: - name: Prettier run: npx --no-install prettier --check . + + - name: Build + run: npm run build diff --git a/.gitignore b/.gitignore index 9e4b161..fbad133 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/build/ /node_modules/ /test-config/ diff --git a/.prettierignore b/.prettierignore index 2f50b84..d61e61b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ +/build/ /test-config/ .vscode diff --git a/README.md b/README.md index 258a73c..1c052e4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This lets you use your favorite shareable config without letting its stylistic c Note that this config _only_ turns rules _off,_ so it only makes sense using it together with some other config. -## Contents +--- @@ -786,7 +786,6 @@ console.log(); Finally, you need to mention the plugin in several places: -- Add `"foobar.js"` to the "files" field in `package.json`. - Add eslint-plugin-foobar to the "devDependencies" field in `package.json`. - Make sure that at least one rule from eslint-plugin-foobar gets used in `.eslintrc.base.js`. - Add it to the list of supported plugins and to the Contributing section in `README.md`. diff --git a/package-real.json b/package-real.json new file mode 100644 index 0000000..43d346c --- /dev/null +++ b/package-real.json @@ -0,0 +1,13 @@ +{ + "name": "eslint-config-prettier", + "version": "6.15.0", + "license": "MIT", + "author": "Simon Lydell", + "description": "Turns off all rules that are unnecessary or might conflict with Prettier.", + "repository": "prettier/eslint-config-prettier", + "bin": "bin/cli.js", + "keywords": ["eslint", "eslintconfig", "prettier"], + "peerDependencies": { + "eslint": ">=7.0.0" + } +} diff --git a/package.json b/package.json index ec52ee5..d2868ad 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,5 @@ { - "name": "eslint-config-prettier", - "version": "6.15.0", - "license": "MIT", - "author": "Simon Lydell", - "description": "Turns off all rules that are unnecessary or might conflict with Prettier.", - "repository": "prettier/eslint-config-prettier", - "files": [ - "bin/", - "@typescript-eslint.js", - "babel.js", - "flowtype.js", - "index.js", - "prettier.js", - "react.js", - "standard.js", - "unicorn.js", - "vue.js" - ], - "bin": "bin/cli.js", - "keywords": [ - "eslint", - "eslintconfig", - "prettier" - ], + "private": true, "scripts": { "doctoc": "doctoc README.md && replace \"\\[\\[([\\w/-]+)\\](?:([^\\[\\]]+)\\[([\\w/-]+)\\])?\\]\" \"[\\$1\\$2\\$3]\" README.md", "prettier": "prettier --write .", @@ -33,9 +10,9 @@ "test:jest": "jest", "test:cli-sanity": "node ./bin/cli.js index.js", "test:cli-sanity-warning": "node ./bin/cli.js react.js ./bin/cli.js", - "test": "npm run test:lint && npm run test:jest && npm run test:cli-sanity && npm run test:cli-sanity-warning" + "test": "npm run test:lint && npm run test:jest && npm run test:cli-sanity && npm run test:cli-sanity-warning && npm run build", + "build": "node scripts/build.js" }, - "dependencies": {}, "devDependencies": { "@typescript-eslint/eslint-plugin": "4.8.2", "@typescript-eslint/parser": "4.8.2", @@ -56,8 +33,5 @@ "replace": "1.2.0", "rimraf": "3.0.2", "typescript": "4.1.2" - }, - "peerDependencies": { - "eslint": ">=7.0.0" } } diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 0000000..8642d8c --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,45 @@ +"use strict"; + +const fs = require("fs"); +const path = require("path"); + +const DIR = path.join(__dirname, ".."); +const BUILD = path.join(DIR, "build"); + +const READ_MORE = + "**[➡️ Full readme](https://github.com/prettier/eslint-config-prettier/)**"; + +const FILES_TO_COPY = [ + { src: "LICENSE" }, + { src: "package-real.json", dest: "package.json" }, + { + src: "README.md", + transform: (content) => content.replace(/^---[^]*/m, READ_MORE), + }, + ...fs + .readdirSync(path.join(DIR, "bin")) + .filter((file) => !file.startsWith(".") && file.endsWith(".js")) + .map((file) => ({ src: path.join("bin", file) })), + ...fs + .readdirSync(DIR) + .filter((file) => !file.startsWith(".") && file.endsWith(".js")) + .map((file) => ({ src: file })), +]; + +if (fs.existsSync(BUILD)) { + fs.rmdirSync(BUILD, { recursive: true }); +} + +fs.mkdirSync(BUILD); + +for (const { src, dest = src, transform } of FILES_TO_COPY) { + if (transform) { + fs.writeFileSync( + path.join(BUILD, dest), + transform(fs.readFileSync(path.join(DIR, src), "utf8")) + ); + } else { + fs.mkdirSync(path.dirname(path.join(BUILD, dest)), { recursive: true }); + fs.copyFileSync(path.join(DIR, src), path.join(BUILD, dest)); + } +} diff --git a/test/rules.test.js b/test/rules.test.js index 84e52ae..8632acd 100644 --- a/test/rules.test.js +++ b/test/rules.test.js @@ -4,7 +4,6 @@ const childProcess = require("child_process"); const fs = require("fs"); const path = require("path"); const rimraf = require("rimraf"); -const pkg = require("../package.json"); const eslintConfig = require("../.eslintrc"); const eslintConfigBase = require("../.eslintrc.base"); @@ -55,14 +54,6 @@ function createTestConfigDir() { }); } -describe("all rule files are listed in package.json", () => { - ruleFiles.forEach((ruleFileName) => { - test(ruleFileName, () => { - expect(pkg.files).toContain(ruleFileName); - }); - }); -}); - describe("all rule files have tests in test-lint/", () => { ruleFiles.forEach((ruleFileName) => { test(ruleFileName, () => {