Skip to content

Commit

Permalink
Merge pull request #24 from atom-community/folderize
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Mar 5, 2021
2 parents 7b92f5f + ccb23e7 commit 5e90b4b
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": ".",
"extends": "./strict",
"ignorePatterns": ["dist/", "node_modules/"]
}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ package-lock.json
# Build directories
dist

strict.js
strict-react.js
spec/fixtures/atom-community
spec/fixtures/atom-minimap
spec/fixtures/aminya
Expand Down
134 changes: 1 addition & 133 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,133 +1 @@
const pluginNodeRules = {
"node/no-exports-assign": "error",
"node/process-exit-as-throw": "error",
"node/shebang": "error",
"node/no-deprecated-api": "error",
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error",
}

const pluginImportExtraRules = {
"import/no-absolute-path": "error",
"import/no-useless-path-segments": "error",
"import/no-deprecated": "error",
"import/no-extraneous-dependencies": "error",
"import/no-unassigned-import": "warn",
"import/no-mutable-exports": "warn",
"import/no-anonymous-default-export": "error",
"import/no-amd": "error",
//// might be too restrictive:
// "import/no-commonjs": "warn",
// "import/no-dynamic-require": "warn", // prevent abusing dynamic require
//// don't work properly:
// "import/unambiguous": "error",
// "import/no-unused-modules": ["warn", {"missingExports": true}],
}

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: 2021,
sourceType: "module",
},
plugins: ["node", "import", "only-warn"],
extends: ["eslint:recommended", "plugin:optimize-regex/all", "plugin:import/recommended", "prettier"],
ignorePatterns: ["node_modules/"],
rules: {
...pluginNodeRules,
...pluginImportExtraRules,
},
overrides: [
{
// Bundled node version with atom has an old ESLint
// TypeScript files
files: ["**/*.ts", "**/*.tsx"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "node", "import", "only-warn"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:optimize-regex/all",
"plugin:import/recommended",
"prettier",
],
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",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
...pluginNodeRules,
...pluginImportExtraRules,
// Buggy on TypeScript:
"import/no-unresolved": "off",
"import/named": "off",
"import/namespace": "off",
},
},
{
// JSON files
files: ["*.json"],
plugins: ["json"],
extends: ["plugin:json/recommended", "prettier"],
rules: {
"json/*": [
"error",
{
allowComments: true,
},
],
},
},
{
// CoffeeScript and CSON files
files: ["**/*.coffee", "**/*.cson"],
parser: "eslint-plugin-coffee",
plugins: ["coffee", "node", "only-warn"],
extends: ["plugin:coffee/eslint-recommended", "plugin:optimize-regex/all", "plugin:coffee/prettier"],
rules: {
...pluginNodeRules,
...pluginImportExtraRules,
},
},
{
// YAML files
files: ["*.yaml", "*.yml"],
plugins: ["yaml"],
extends: ["plugin:yaml/recommended"],
},
],
settings: {
"import/core-modules": ["atom", "electron"],
// support TypeScript and Coffee importing
"import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx", ".coffee"],
"import/external-module-folders": ["node_modules", "node_modules/@types"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
node: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx", ".coffee"],
},
},
},
}
module.exports = require("./src/index.js")
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"test.lint": "eslint .",
"test": "node ./spec/test.js",
"clean": "shx rm -rf ./spec/fixtures/atom-community ./spec/fixtures/atom-minimap ./spec/fixtures/steelbrain ./strict.js ./strict-react.js",
"build.strict": "node ./scripts/build.strict.js",
"prepare": "npm run build.strict",
"bump": "ncu -u -x coffeescript"
},
"dependencies": {
Expand Down
24 changes: 1 addition & 23 deletions react.js
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
const base = require("./index.js")

let overrides = base.overrides
// TypeScript:
overrides[0] = {
...overrides[0],
plugins: ["react", ...overrides[0].plugins],
extends: ["plugin:react/recommended", ...overrides[0].extends],
rules: overrides[0].rules,
}

module.exports = {
...base,
plugins: ["react", ...base.plugins],
extends: ["plugin:react/recommended", ...base.extends],
overrides: overrides,
settings: {
...(base.settings || {}),
react: {
version: "detect",
},
},
}
module.exports = require("./src/index-react.js")
22 changes: 0 additions & 22 deletions scripts/build.strict.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/coffeescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { pluginNodeRules } = require("./plugin-node-rules")
const { pluginImportRulesExtra } = require("./plugin-import-rules")

exports.coffeeConfig = {
// CoffeeScript files
files: ["**/*.coffee"],
parser: "eslint-plugin-coffee",
plugins: ["coffee", "node", "only-warn"],
extends: ["plugin:coffee/eslint-recommended", "plugin:optimize-regex/all", "plugin:coffee/prettier"],
rules: {
...pluginNodeRules,
...pluginImportRulesExtra,
},
}
6 changes: 6 additions & 0 deletions src/cson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { coffeeConfig } = require("./coffeescript")

exports.csonConfig = {
...coffeeConfig,
files: ["**/*.cson"],
}
25 changes: 25 additions & 0 deletions src/index-react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const base = require("./index.js")
const { tsConfig } = require("./typescript")

module.exports = {
...base,
plugins: ["react", ...base.plugins],
extends: ["plugin:react/recommended", ...base.extends],
overrides: [
// TypeScript:
{
...tsConfig,
plugins: ["react", ...tsConfig.plugins],
extends: ["plugin:react/recommended", ...tsConfig.extends],
rules: tsConfig.rules,
},
// The rest is the same
...base.overrides.slice(1),
],
settings: {
...(base.settings || {}),
react: {
version: "detect",
},
},
}
15 changes: 15 additions & 0 deletions src/index-strict-react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const nonStrictConfig = require("./index-react")

// remove only-warn from javascript
if (nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn") {
nonStrictConfig.plugins.pop()
}

// remove only-warn from overrides
nonStrictConfig.overrides.forEach((overrides) => {
if (overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
overrides.plugins.pop()
}
})

module.exports = nonStrictConfig
15 changes: 15 additions & 0 deletions src/index-strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const nonStrictConfig = require("./index")

// remove only-warn from javascript
if (nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn") {
nonStrictConfig.plugins.pop()
}

// remove only-warn from overrides
nonStrictConfig.overrides.forEach((overrides) => {
if (overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
overrides.plugins.pop()
}
})

module.exports = nonStrictConfig
27 changes: 27 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { jsConfig } = require("./javascript")
const { tsConfig } = require("./typescript")
const { coffeeConfig } = require("./coffeescript")
const { jsonConfig } = require("./json")
const { csonConfig } = require("./cson")
const { yamlConfig } = require("./yaml")
const { pluginImportSettings } = require("./plugin-import-rules")

module.exports = {
root: true,
env: {
atomtest: true,
es6: true,
node: true,
browser: true,
jasmine: true,
},
globals: {
atom: "readonly",
measure: "readonly",
},
...jsConfig,
overrides: [tsConfig, coffeeConfig, jsonConfig, csonConfig, yamlConfig],
settings: {
...pluginImportSettings,
},
}
20 changes: 20 additions & 0 deletions src/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { pluginNodeRules } = require("./plugin-node-rules")
const { pluginImportRulesExtra } = require("./plugin-import-rules")

exports.jsConfig = {
parser: "babel-eslint",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2021,
sourceType: "module",
},
plugins: ["node", "import", "only-warn"],
extends: ["eslint:recommended", "plugin:optimize-regex/all", "plugin:import/recommended", "prettier"],
ignorePatterns: ["node_modules/"],
rules: {
...pluginNodeRules,
...pluginImportRulesExtra,
},
}
14 changes: 14 additions & 0 deletions src/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.jsonConfig = {
// JSON files
files: ["*.json"],
plugins: ["json"],
extends: ["plugin:json/recommended", "prettier"],
rules: {
"json/*": [
"error",
{
allowComments: true,
},
],
},
}
38 changes: 38 additions & 0 deletions src/plugin-import-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
exports.pluginImportRulesExtra = {
"import/no-absolute-path": "error",
"import/no-useless-path-segments": "error",
"import/no-deprecated": "error",
"import/no-extraneous-dependencies": "error",
"import/no-unassigned-import": "warn",
"import/no-mutable-exports": "warn",
"import/no-anonymous-default-export": "error",
"import/no-amd": "error",
//// might be too restrictive:
// "import/no-commonjs": "warn",
// "import/no-dynamic-require": "warn", // prevent abusing dynamic require
//// don't work properly:
// "import/unambiguous": "error",
// "import/no-unused-modules": ["warn", {"missingExports": true}],
}

exports.pluginImportTypeScriptRulesExtra = {
// Buggy on TypeScript:
"import/no-unresolved": "off",
"import/named": "off",
"import/namespace": "off",
}

exports.pluginImportSettings = {
"import/core-modules": ["atom", "electron"],
// support TypeScript and Coffee importing
"import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx", ".coffee"],
"import/external-module-folders": ["node_modules", "node_modules/@types"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
node: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx", ".coffee"],
},
},
}
8 changes: 8 additions & 0 deletions src/plugin-node-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.pluginNodeRules = {
"node/no-exports-assign": "error",
"node/process-exit-as-throw": "error",
"node/shebang": "error",
"node/no-deprecated-api": "error",
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error",
}
Loading

0 comments on commit 5e90b4b

Please sign in to comment.