diff --git a/.gitignore b/.gitignore index 106bb0d..d53d774 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ package-lock.json # Build directories dist + +strict.js +strict-react.js diff --git a/package.json b/package.json index 1ee355b..6833907 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,8 @@ "repository": "https://github.com/atom-ide-community/eslint-config-atomic", "license": "MIT", "scripts": { + "build.strict": "node ./scripts/build.strict.js", + "prepare": "npm run build.strict", "bump": "ncu -u -x coffeescript" }, "dependencies": { diff --git a/react.js b/react.js index 13f5bd9..d539fa8 100644 --- a/react.js +++ b/react.js @@ -1,87 +1,25 @@ +const base = require("./index.js") + +let overrides = base.overrides +overrides[0] = { + "plugins": ["react", "@typescript-eslint", "only-warn"], + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "prettier", + "prettier/@typescript-eslint", + "prettier/react" + ], + rules: overrides[0].rules +} + module.exports = { - // JS Files - "root": true, - "env": { - "atomtest": true, - "es6": true, - "node": true, - "browser": true, - "jasmine": true - }, - "globals": { - "atom": "readonly", - "measure": "readonly" - }, - "parser": "babel-eslint", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 2018, - "sourceType": "module" - }, + ...base, "plugins": ["react", "only-warn"], "extends": ["eslint:recommended", "plugin:react/recommended", "prettier", "prettier/react"], - "ignorePatterns": ["node_modules/"], - "overrides": [ - { - // Bundled node version with atom has an old ESLint - // TypeScript files - "files": ["**/*.ts", "**/*.tsx"], - "parser": "@typescript-eslint/parser", - "plugins": ["react", "@typescript-eslint", "only-warn"], - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - "prettier/@typescript-eslint", - "prettier/react" - ], - "rules": { - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/camelcase": "off", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/member-delimiter-style": "off" - } - }, - { - // JSON files - "files": ["*.json"], - "plugins": ["json"], - "extends": ["prettier", "plugin:json/recommended"], - "rules": { - "json/*": [ - "error", - { - "allowComments": true - } - ] - } - }, - { - // CoffeeScript files - "files": ["**/*.coffee"], - "parser": "eslint-plugin-coffee", - "plugins": ["coffee", "only-warn"], - "extends": ["plugin:coffee/eslint-recommended"] - }, - { - // YAML files - "files": ["*.yaml", "*.yml"], - "plugins": ["yaml"], - "extends": ["plugin:yaml/recommended"] - }, - // CSON files (use coffee) - { - "files": ["**/*.cson"], - "parser": "eslint-plugin-coffee", - "plugins": ["coffee", "only-warn"], - "extends": ["plugin:coffee/eslint-recommended"] - } - ], + "overrides": overrides, "settings": { "react": { "version": "detect" diff --git a/scripts/build.strict.js b/scripts/build.strict.js new file mode 100644 index 0000000..69ce117 --- /dev/null +++ b/scripts/build.strict.js @@ -0,0 +1,22 @@ +// script to generate the strict versions (without only-warn) + +const { readFile, writeFile } = require("fs").promises +const { join, dirname, basename } = require("path") + +const fileMap = { + "index.js": "strict.js", + "react.js": "strict-react.js" +} + +;(async function main(){ + const root = dirname(__dirname) + const files = ["index.js", "react.js"] + + const filesPaths = files.map((file) => join(root, file)) + + filesPaths.forEach(async (filePath) => { + const text = (await readFile(filePath)).toString() + const newText = text.replace(/"only-warn"/g, "").replace("index.js", "strict.js") + await writeFile(join(root, fileMap[basename(filePath)]), newText) + }) +})() diff --git a/strict-react.js b/strict-react.js deleted file mode 100644 index 4f4f8c0..0000000 --- a/strict-react.js +++ /dev/null @@ -1,90 +0,0 @@ -module.exports = { - // JS Files - "root": true, - "env": { - "atomtest": true, - "es6": true, - "node": true, - "browser": true, - "jasmine": true - }, - "globals": { - "atom": "readonly", - "measure": "readonly" - }, - "parser": "babel-eslint", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 2018, - "sourceType": "module" - }, - "plugins": ["react"], - "extends": ["eslint:recommended", "plugin:react/recommended", "prettier", "prettier/react"], - "ignorePatterns": ["node_modules/"], - "overrides": [ - { - // Bundled node version with atom has an old ESLint - // TypeScript files - "files": ["**/*.ts", "**/*.tsx"], - "parser": "@typescript-eslint/parser", - "plugins": ["react", "@typescript-eslint"], - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - "prettier/@typescript-eslint", - "prettier/react" - ], - "rules": { - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/camelcase": "off", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/member-delimiter-style": "off" - } - }, - { - // JSON files - "files": ["*.json"], - "plugins": ["json"], - "extends": ["prettier", "plugin:json/recommended"], - "rules": { - "json/*": [ - "error", - { - "allowComments": true - } - ] - } - }, - { - // CoffeeScript files - "files": ["**/*.coffee"], - "parser": "eslint-plugin-coffee", - "plugins": ["coffee"], - "extends": ["plugin:coffee/eslint-recommended"] - }, - { - // YAML files - "files": ["*.yaml", "*.yml"], - "plugins": ["yaml"], - "extends": ["plugin:yaml/recommended"] - }, - // CSON files (use coffee) - { - "files": ["**/*.cson"], - "parser": "eslint-plugin-coffee", - "plugins": ["coffee", "only-warn"], - "extends": ["plugin:coffee/eslint-recommended"] - } - ], - "settings": { - "react": { - "version": "detect" - } - } -} diff --git a/strict.js b/strict.js deleted file mode 100644 index 3c68873..0000000 --- a/strict.js +++ /dev/null @@ -1,84 +0,0 @@ -module.exports = { - // JS Files - "root": true, - "env": { - "atomtest": true, - "es6": true, - "node": true, - "browser": true, - "jasmine": true - }, - "globals": { - "atom": "readonly", - "measure": "readonly" - }, - "parser": "babel-eslint", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 2018, - "sourceType": "module" - }, - "plugins": [], - "extends": ["eslint:recommended", "prettier"], - "ignorePatterns": ["node_modules/"], - "overrides": [ - { - // Bundled node version with atom has an old ESLint - // TypeScript files - "files": ["**/*.ts", "**/*.tsx"], - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - "prettier/@typescript-eslint" - ], - "rules": { - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/camelcase": "off", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/member-delimiter-style": "off" - } - }, - { - // JSON files - "files": ["*.json"], - "plugins": ["json"], - "extends": ["prettier", "plugin:json/recommended"], - "rules": { - "json/*": [ - "error", - { - "allowComments": true - } - ] - } - }, - { - // CoffeeScript files - "files": ["**/*.coffee"], - "parser": "eslint-plugin-coffee", - "plugins": ["coffee"], - "extends": ["plugin:coffee/eslint-recommended"] - }, - { - // YAML files - "files": ["*.yaml", "*.yml"], - "plugins": ["yaml"], - "extends": ["plugin:yaml/recommended"] - }, - // CSON files (use coffee) - { - "files": ["**/*.cson"], - "parser": "eslint-plugin-coffee", - "plugins": ["coffee", "only-warn"], - "extends": ["plugin:coffee/eslint-recommended"] - } - ] -}