Skip to content

Commit

Permalink
Update .eslintrc.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Apr 3, 2020
1 parent c030d80 commit cc70569
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 80 deletions.
151 changes: 72 additions & 79 deletions .eslintrc.js
@@ -1,13 +1,44 @@
"use strict";

const internalFiles = [
"**/cli-engine/**/*",
"**/init/**/*",
"**/linter/**/*",
"**/rule-tester/**/*",
"**/rules/**/*",
"**/source-code/**/*"
];
const path = require("path");

const INTERNAL_FILES = {
CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",
INIT_PATTERN: "lib/init/**/*",
LINTER_PATTERN: "lib/linter/**/*",
RULE_TESTER_PATTERN: "lib/rule-tester/**/*",
RULES_PATTERN: "lib/rules/**/*",
SOURCE_CODE_PATTERN: "lib/source-code/**/*"
};

/**
* Resolve an absolute path or glob pattern.
* @param {string} pathOrPattern the path or glob pattern.
* @returns {string} The resolved path or glob pattern.
*/
function resolveAbsPath(pathOrPattern) {
return path.resolve(__dirname, pathOrPattern);
}

/**
* Create an array of `no-restricted-require` entries for ESLint's core files.
* @param {string} [pattern] The glob pattern to create the entries for.
* @returns {Object[]} The array of `no-restricted-require` entries.
*/
function createInternalFilesPatterns(pattern = null) {
return Object.values(INTERNAL_FILES)
.filter(p => p !== pattern)
.map(p => ({
name: [

// Disallow all children modules.
resolveAbsPath(p),

// Allow the main `index.js` module.
`!${resolveAbsPath(p.replace(/\*\*\/\*$/u, "index.js"))}`
]
}));
}

module.exports = {
root: true,
Expand Down Expand Up @@ -84,106 +115,68 @@ module.exports = {
{
files: ["lib/*"],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns()
]]
}
},
{
files: ["lib/cli-engine/**/*"],
files: [INTERNAL_FILES.CLI_ENGINE_PATTERN],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles,
"**/init"
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.CLI_ENGINE_PATTERN)
]]
}
},
{
files: ["lib/init/**/*"],
files: [INTERNAL_FILES.INIT_PATTERN],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles,
"**/rule-tester"
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.INIT_PATTERN)
]]
}
},
{
files: ["lib/linter/**/*"],
files: [INTERNAL_FILES.LINTER_PATTERN],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles,
"fs",
"**/cli-engine",
"**/init",
"**/rule-tester"
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.LINTER_PATTERN),
"fs"
]]
}
},
{
files: ["lib/rules/**/*"],
files: [INTERNAL_FILES.RULES_PATTERN],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles,
"fs",
"**/cli-engine",
"**/init",
"**/linter",
"**/rule-tester",
"**/source-code"
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.RULES_PATTERN),
"fs"
]]
}
},
{
files: ["lib/shared/**/*"],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles,
"**/cli-engine",
"**/init",
"**/linter",
"**/rule-tester",
"**/source-code"
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns()
]]
}
},
{
files: ["lib/source-code/**/*"],
files: [INTERNAL_FILES.SOURCE_CODE_PATTERN],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles,
"fs",
"**/cli-engine",
"**/init",
"**/linter",
"**/rule-tester",
"**/rules"
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.SOURCE_CODE_PATTERN),
"fs"
]]
}
},
{
files: ["lib/rule-tester/**/*"],
files: [INTERNAL_FILES.RULE_TESTER_PATTERN],
rules: {
"no-restricted-modules": ["error", {
patterns: [
...internalFiles,
"**/cli-engine",
"**/init"
]
}]
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.RULE_TESTER_PATTERN)
]]
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion lib/init/source-code-utils.js
Expand Up @@ -23,7 +23,7 @@ const { CLIEngine } = require("../cli-engine");
* TODO1: Expose the API that enumerates target files.
* TODO2: Extract the creation logic of `SourceCode` from `Linter` class.
*/
const { getCLIEngineInternalSlots } = require("../cli-engine/cli-engine"); // eslint-disable-line no-restricted-modules
const { getCLIEngineInternalSlots } = require("../cli-engine/cli-engine"); // eslint-disable-line node/no-restricted-require

const debug = require("debug")("eslint:source-code-utils");

Expand Down

0 comments on commit cc70569

Please sign in to comment.