From 82669fa66670a00988db5b1d10fe8f3bf30be84e Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 26 Aug 2020 14:25:21 -0700 Subject: [PATCH] Chore: Extract some functionality to eslintrc (refs #13481) (#13613) --- conf/environments.js | 180 ----------------- lib/cli-engine/cli-engine.js | 4 +- lib/cli-engine/config-array-factory.js | 2 +- lib/eslint/eslint.js | 8 +- lib/init/autoconfig.js | 2 +- lib/init/config-initializer.js | 4 +- lib/linter/config-comment-parser.js | 2 +- lib/linter/linter.js | 9 +- lib/shared/config-ops.js | 142 -------------- lib/shared/config-validator.js | 4 +- lib/shared/naming.js | 109 ----------- package.json | 1 + tests/lib/shared/config-ops.js | 261 ------------------------- tests/lib/shared/naming.js | 76 ------- 14 files changed, 23 insertions(+), 781 deletions(-) delete mode 100644 conf/environments.js delete mode 100644 lib/shared/config-ops.js delete mode 100644 lib/shared/naming.js delete mode 100644 tests/lib/shared/config-ops.js delete mode 100644 tests/lib/shared/naming.js diff --git a/conf/environments.js b/conf/environments.js deleted file mode 100644 index 096c6003179..00000000000 --- a/conf/environments.js +++ /dev/null @@ -1,180 +0,0 @@ -/* - * STOP!!! DO NOT MODIFY. - * - * This file is part of the ongoing work to move the eslintrc-style config - * system into the @eslint/eslintrc package. This file needs to remain - * unchanged in order for this work to proceed. - * - * If you think you need to change this file, please contact @nzakas first. - * - * Thanks in advance for your cooperation. - */ - -/** - * @fileoverview Defines environment settings and globals. - * @author Elan Shanker - */ -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const globals = require("globals"); - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -/** - * Get the object that has difference. - * @param {Record} current The newer object. - * @param {Record} prev The older object. - * @returns {Record} The difference object. - */ -function getDiff(current, prev) { - const retv = {}; - - for (const [key, value] of Object.entries(current)) { - if (!Object.hasOwnProperty.call(prev, key)) { - retv[key] = value; - } - } - - return retv; -} - -const newGlobals2015 = getDiff(globals.es2015, globals.es5); // 19 variables such as Promise, Map, ... -const newGlobals2017 = { - Atomics: false, - SharedArrayBuffer: false -}; -const newGlobals2020 = { - BigInt: false, - BigInt64Array: false, - BigUint64Array: false, - globalThis: false -}; - -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ - -/** @type {Map} */ -module.exports = new Map(Object.entries({ - - // Language - builtin: { - globals: globals.es5 - }, - es6: { - globals: newGlobals2015, - parserOptions: { - ecmaVersion: 6 - } - }, - es2015: { - globals: newGlobals2015, - parserOptions: { - ecmaVersion: 6 - } - }, - es2017: { - globals: { ...newGlobals2015, ...newGlobals2017 }, - parserOptions: { - ecmaVersion: 8 - } - }, - es2020: { - globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 }, - parserOptions: { - ecmaVersion: 11 - } - }, - - // Platforms - browser: { - globals: globals.browser - }, - node: { - globals: globals.node, - parserOptions: { - ecmaFeatures: { - globalReturn: true - } - } - }, - "shared-node-browser": { - globals: globals["shared-node-browser"] - }, - worker: { - globals: globals.worker - }, - serviceworker: { - globals: globals.serviceworker - }, - - // Frameworks - commonjs: { - globals: globals.commonjs, - parserOptions: { - ecmaFeatures: { - globalReturn: true - } - } - }, - amd: { - globals: globals.amd - }, - mocha: { - globals: globals.mocha - }, - jasmine: { - globals: globals.jasmine - }, - jest: { - globals: globals.jest - }, - phantomjs: { - globals: globals.phantomjs - }, - jquery: { - globals: globals.jquery - }, - qunit: { - globals: globals.qunit - }, - prototypejs: { - globals: globals.prototypejs - }, - shelljs: { - globals: globals.shelljs - }, - meteor: { - globals: globals.meteor - }, - mongo: { - globals: globals.mongo - }, - protractor: { - globals: globals.protractor - }, - applescript: { - globals: globals.applescript - }, - nashorn: { - globals: globals.nashorn - }, - atomtest: { - globals: globals.atomtest - }, - embertest: { - globals: globals.embertest - }, - webextensions: { - globals: globals.webextensions - }, - greasemonkey: { - globals: globals.greasemonkey - } -})); diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index 802a405c04a..70c6f6f39f7 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -19,8 +19,8 @@ const fs = require("fs"); const path = require("path"); const defaultOptions = require("../../conf/default-cli-options"); const pkg = require("../../package.json"); -const ConfigOps = require("../shared/config-ops"); -const naming = require("../shared/naming"); +const ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"); +const naming = require("@eslint/eslintrc/lib/shared/naming"); const ModuleResolver = require("../shared/relative-module-resolver"); const { Linter } = require("../linter"); const builtInRules = require("../rules"); diff --git a/lib/cli-engine/config-array-factory.js b/lib/cli-engine/config-array-factory.js index e552c4e00a9..e81494ed86a 100644 --- a/lib/cli-engine/config-array-factory.js +++ b/lib/cli-engine/config-array-factory.js @@ -56,7 +56,7 @@ const path = require("path"); const importFresh = require("import-fresh"); const stripComments = require("strip-json-comments"); const { validateConfigSchema } = require("../shared/config-validator"); -const naming = require("../shared/naming"); +const naming = require("@eslint/eslintrc/lib/shared/naming"); const ModuleResolver = require("../shared/relative-module-resolver"); const { ConfigArray, diff --git a/lib/eslint/eslint.js b/lib/eslint/eslint.js index d195aab09f1..a51ffbfe41a 100644 --- a/lib/eslint/eslint.js +++ b/lib/eslint/eslint.js @@ -15,7 +15,13 @@ const fs = require("fs"); const { promisify } = require("util"); const { CLIEngine, getCLIEngineInternalSlots } = require("../cli-engine/cli-engine"); const BuiltinRules = require("../rules"); -const { getRuleSeverity } = require("../shared/config-ops"); +const { + Legacy: { + ConfigOps: { + getRuleSeverity + } + } +} = require("@eslint/eslintrc"); const { version } = require("../../package.json"); //------------------------------------------------------------------------------ diff --git a/lib/init/autoconfig.js b/lib/init/autoconfig.js index 2b0aa12ac13..0ace177aa16 100644 --- a/lib/init/autoconfig.js +++ b/lib/init/autoconfig.js @@ -11,7 +11,7 @@ const lodash = require("lodash"), recConfig = require("../../conf/eslint-recommended"), - ConfigOps = require("../shared/config-ops"), + ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"), { Linter } = require("../linter"), configRule = require("./config-rule"); diff --git a/lib/init/config-initializer.js b/lib/init/config-initializer.js index e14f1cb0824..da942e4b5fe 100644 --- a/lib/init/config-initializer.js +++ b/lib/init/config-initializer.js @@ -17,9 +17,9 @@ const util = require("util"), semver = require("semver"), espree = require("espree"), recConfig = require("../../conf/eslint-recommended"), - ConfigOps = require("../shared/config-ops"), + ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"), log = require("../shared/logging"), - naming = require("../shared/naming"), + naming = require("@eslint/eslintrc/lib/shared/naming"), ModuleResolver = require("../shared/relative-module-resolver"), autoconfig = require("./autoconfig.js"), ConfigFile = require("./config-file"), diff --git a/lib/linter/config-comment-parser.js b/lib/linter/config-comment-parser.js index 067d0248030..07bbead281c 100644 --- a/lib/linter/config-comment-parser.js +++ b/lib/linter/config-comment-parser.js @@ -11,7 +11,7 @@ //------------------------------------------------------------------------------ const levn = require("levn"), - ConfigOps = require("../shared/config-ops"); + ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"); const debug = require("debug")("eslint:config-comment-parser"); diff --git a/lib/linter/linter.js b/lib/linter/linter.js index f9f38790b3c..5c1a8d78aa1 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -16,11 +16,11 @@ const evk = require("eslint-visitor-keys"), espree = require("espree"), lodash = require("lodash"), - BuiltInEnvironments = require("../../conf/environments"), + BuiltInEnvironments = require("@eslint/eslintrc/conf/environments"), pkg = require("../../package.json"), astUtils = require("../shared/ast-utils"), - ConfigOps = require("../shared/config-ops"), - validator = require("../shared/config-validator"), + ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"), + ConfigValidator = require("@eslint/eslintrc/lib/shared/config-validator"), Traverser = require("../shared/traverser"), { SourceCode } = require("../source-code"), CodePathAnalyzer = require("./code-path-analysis/code-path-analyzer"), @@ -293,6 +293,9 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) { const exportedVariables = {}; const problems = []; const disableDirectives = []; + const validator = new ConfigValidator({ + builtInRules: Rules + }); ast.comments.filter(token => token.type !== "Shebang").forEach(comment => { const trimmedCommentText = stripDirectiveComment(comment.value); diff --git a/lib/shared/config-ops.js b/lib/shared/config-ops.js deleted file mode 100644 index 97e34b0a9da..00000000000 --- a/lib/shared/config-ops.js +++ /dev/null @@ -1,142 +0,0 @@ -/* - * STOP!!! DO NOT MODIFY. - * - * This file is part of the ongoing work to move the eslintrc-style config - * system into the @eslint/eslintrc package. This file needs to remain - * unchanged in order for this work to proceed. - * - * If you think you need to change this file, please contact @nzakas first. - * - * Thanks in advance for your cooperation. - */ - -/** - * @fileoverview Config file operations. This file must be usable in the browser, - * so no Node-specific code can be here. - * @author Nicholas C. Zakas - */ -"use strict"; - -//------------------------------------------------------------------------------ -// Private -//------------------------------------------------------------------------------ - -const RULE_SEVERITY_STRINGS = ["off", "warn", "error"], - RULE_SEVERITY = RULE_SEVERITY_STRINGS.reduce((map, value, index) => { - map[value] = index; - return map; - }, {}), - VALID_SEVERITIES = [0, 1, 2, "off", "warn", "error"]; - -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ - -module.exports = { - - /** - * Normalizes the severity value of a rule's configuration to a number - * @param {(number|string|[number, ...*]|[string, ...*])} ruleConfig A rule's configuration value, generally - * received from the user. A valid config value is either 0, 1, 2, the string "off" (treated the same as 0), - * the string "warn" (treated the same as 1), the string "error" (treated the same as 2), or an array - * whose first element is one of the above values. Strings are matched case-insensitively. - * @returns {(0|1|2)} The numeric severity value if the config value was valid, otherwise 0. - */ - getRuleSeverity(ruleConfig) { - const severityValue = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig; - - if (severityValue === 0 || severityValue === 1 || severityValue === 2) { - return severityValue; - } - - if (typeof severityValue === "string") { - return RULE_SEVERITY[severityValue.toLowerCase()] || 0; - } - - return 0; - }, - - /** - * Converts old-style severity settings (0, 1, 2) into new-style - * severity settings (off, warn, error) for all rules. Assumption is that severity - * values have already been validated as correct. - * @param {Object} config The config object to normalize. - * @returns {void} - */ - normalizeToStrings(config) { - - if (config.rules) { - Object.keys(config.rules).forEach(ruleId => { - const ruleConfig = config.rules[ruleId]; - - if (typeof ruleConfig === "number") { - config.rules[ruleId] = RULE_SEVERITY_STRINGS[ruleConfig] || RULE_SEVERITY_STRINGS[0]; - } else if (Array.isArray(ruleConfig) && typeof ruleConfig[0] === "number") { - ruleConfig[0] = RULE_SEVERITY_STRINGS[ruleConfig[0]] || RULE_SEVERITY_STRINGS[0]; - } - }); - } - }, - - /** - * Determines if the severity for the given rule configuration represents an error. - * @param {int|string|Array} ruleConfig The configuration for an individual rule. - * @returns {boolean} True if the rule represents an error, false if not. - */ - isErrorSeverity(ruleConfig) { - return module.exports.getRuleSeverity(ruleConfig) === 2; - }, - - /** - * Checks whether a given config has valid severity or not. - * @param {number|string|Array} ruleConfig The configuration for an individual rule. - * @returns {boolean} `true` if the configuration has valid severity. - */ - isValidSeverity(ruleConfig) { - let severity = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig; - - if (typeof severity === "string") { - severity = severity.toLowerCase(); - } - return VALID_SEVERITIES.indexOf(severity) !== -1; - }, - - /** - * Checks whether every rule of a given config has valid severity or not. - * @param {Object} config The configuration for rules. - * @returns {boolean} `true` if the configuration has valid severity. - */ - isEverySeverityValid(config) { - return Object.keys(config).every(ruleId => this.isValidSeverity(config[ruleId])); - }, - - /** - * Normalizes a value for a global in a config - * @param {(boolean|string|null)} configuredValue The value given for a global in configuration or in - * a global directive comment - * @returns {("readable"|"writeable"|"off")} The value normalized as a string - * @throws Error if global value is invalid - */ - normalizeConfigGlobal(configuredValue) { - switch (configuredValue) { - case "off": - return "off"; - - case true: - case "true": - case "writeable": - case "writable": - return "writable"; - - case null: - case false: - case "false": - case "readable": - case "readonly": - return "readonly"; - - default: - throw new Error(`'${configuredValue}' is not a valid configuration for a global (use 'readonly', 'writable', or 'off')`); - } - } -}; diff --git a/lib/shared/config-validator.js b/lib/shared/config-validator.js index e0e4f6fe811..03b32f1c918 100644 --- a/lib/shared/config-validator.js +++ b/lib/shared/config-validator.js @@ -24,9 +24,9 @@ const util = require("util"), configSchema = require("../../conf/config-schema"), - BuiltInEnvironments = require("../../conf/environments"), + BuiltInEnvironments = require("@eslint/eslintrc/conf/environments"), BuiltInRules = require("../rules"), - ConfigOps = require("./config-ops"), + ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"), { emitDeprecationWarning } = require("./deprecation-warnings"); const ajv = require("./ajv")(); diff --git a/lib/shared/naming.js b/lib/shared/naming.js deleted file mode 100644 index 2d070c95dd4..00000000000 --- a/lib/shared/naming.js +++ /dev/null @@ -1,109 +0,0 @@ -/* - * STOP!!! DO NOT MODIFY. - * - * This file is part of the ongoing work to move the eslintrc-style config - * system into the @eslint/eslintrc package. This file needs to remain - * unchanged in order for this work to proceed. - * - * If you think you need to change this file, please contact @nzakas first. - * - * Thanks in advance for your cooperation. - */ - -/** - * @fileoverview Common helpers for naming of plugins, formatters and configs - */ -"use strict"; - -const NAMESPACE_REGEX = /^@.*\//iu; - -/** - * Brings package name to correct format based on prefix - * @param {string} name The name of the package. - * @param {string} prefix Can be either "eslint-plugin", "eslint-config" or "eslint-formatter" - * @returns {string} Normalized name of the package - * @private - */ -function normalizePackageName(name, prefix) { - let normalizedName = name; - - /** - * On Windows, name can come in with Windows slashes instead of Unix slashes. - * Normalize to Unix first to avoid errors later on. - * https://github.com/eslint/eslint/issues/5644 - */ - if (normalizedName.includes("\\")) { - normalizedName = normalizedName.replace(/\\/gu, "/"); - } - - if (normalizedName.charAt(0) === "@") { - - /** - * it's a scoped package - * package name is the prefix, or just a username - */ - const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`, "u"), - scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, "u"); - - if (scopedPackageShortcutRegex.test(normalizedName)) { - normalizedName = normalizedName.replace(scopedPackageShortcutRegex, `$1/${prefix}`); - } else if (!scopedPackageNameRegex.test(normalizedName.split("/")[1])) { - - /** - * for scoped packages, insert the prefix after the first / unless - * the path is already @scope/eslint or @scope/eslint-xxx-yyy - */ - normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`); - } - } else if (!normalizedName.startsWith(`${prefix}-`)) { - normalizedName = `${prefix}-${normalizedName}`; - } - - return normalizedName; -} - -/** - * Removes the prefix from a fullname. - * @param {string} fullname The term which may have the prefix. - * @param {string} prefix The prefix to remove. - * @returns {string} The term without prefix. - */ -function getShorthandName(fullname, prefix) { - if (fullname[0] === "@") { - let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, "u").exec(fullname); - - if (matchResult) { - return matchResult[1]; - } - - matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, "u").exec(fullname); - if (matchResult) { - return `${matchResult[1]}/${matchResult[2]}`; - } - } else if (fullname.startsWith(`${prefix}-`)) { - return fullname.slice(prefix.length + 1); - } - - return fullname; -} - -/** - * Gets the scope (namespace) of a term. - * @param {string} term The term which may have the namespace. - * @returns {string} The namespace of the term if it has one. - */ -function getNamespaceFromTerm(term) { - const match = term.match(NAMESPACE_REGEX); - - return match ? match[0] : ""; -} - -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ - -module.exports = { - normalizePackageName, - getShorthandName, - getNamespaceFromTerm -}; diff --git a/package.json b/package.json index 01d38d47801..09efdfa9fef 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "bugs": "https://github.com/eslint/eslint/issues/", "dependencies": { "@babel/code-frame": "^7.0.0", + "@eslint/eslintrc": "^0.1.0", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", diff --git a/tests/lib/shared/config-ops.js b/tests/lib/shared/config-ops.js deleted file mode 100644 index 59a2845ec6f..00000000000 --- a/tests/lib/shared/config-ops.js +++ /dev/null @@ -1,261 +0,0 @@ -/* - * STOP!!! DO NOT MODIFY. - * - * This file is part of the ongoing work to move the eslintrc-style config - * system into the @eslint/eslintrc package. This file needs to remain - * unchanged in order for this work to proceed. - * - * If you think you need to change this file, please contact @nzakas first. - * - * Thanks in advance for your cooperation. - */ - -/** - * @fileoverview Tests for ConfigOps - * @author Nicholas C. Zakas - */ -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const assert = require("chai").assert, - util = require("util"), - ConfigOps = require("../../../lib/shared/config-ops"); - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -describe("ConfigOps", () => { - - describe("getRuleSeverity()", () => { - const EXPECTED_RESULTS = new Map([ - [0, 0], - [1, 1], - [2, 2], - [[0], 0], - [[1], 1], - [[2], 2], - ["off", 0], - ["warn", 1], - ["error", 2], - [["off"], 0], - [["warn"], 1], - [["error"], 2], - ["OFF", 0], - ["wArN", 1], - [["ErRoR"], 2], - ["invalid config", 0], - [["invalid config"], 0], - [3, 0], - [[3], 0], - [1.5, 0], - [[1.5], 0] - ]); - - for (const key of EXPECTED_RESULTS.keys()) { - it(`returns ${util.inspect(EXPECTED_RESULTS.get(key))} for ${util.inspect(key)}`, () => { - assert.strictEqual(ConfigOps.getRuleSeverity(key), EXPECTED_RESULTS.get(key)); - }); - } - }); - - describe("normalizeToStrings()", () => { - it("should convert 2 rule setting to error when rule has just a severity", () => { - const config = { - rules: { - foo: 2, - bar: 2 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: "error", - bar: "error" - } - }); - }); - - it("should convert 2 rule setting to error when rule has array with severity", () => { - const config = { - rules: { - foo: [2, "something"], - bar: 2 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: ["error", "something"], - bar: "error" - } - }); - }); - - it("should convert 1 rule setting to warn when rule has just a severity", () => { - const config = { - rules: { - foo: 1, - bar: 1 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: "warn", - bar: "warn" - } - }); - }); - - it("should convert 1 rule setting to warn when rule has array with severity", () => { - const config = { - rules: { - foo: [1, "something"], - bar: 1 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: ["warn", "something"], - bar: "warn" - } - }); - }); - - it("should convert 0 rule setting to off when rule has just a severity", () => { - const config = { - rules: { - foo: 0, - bar: 0 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: "off", - bar: "off" - } - }); - }); - - it("should convert 0 rule setting to off when rule has array with severity", () => { - const config = { - rules: { - foo: [0, "something"], - bar: 0 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: ["off", "something"], - bar: "off" - } - }); - }); - - it("should convert 256 rule setting to off when rule has just a severity", () => { - const config = { - rules: { - foo: 256, - bar: 256 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: "off", - bar: "off" - } - }); - }); - - it("should convert 256 rule setting to off when rule has array with severity", () => { - const config = { - rules: { - foo: [256, "something"], - bar: 256 - } - }; - - ConfigOps.normalizeToStrings(config); - - assert.deepStrictEqual(config, { - rules: { - foo: ["off", "something"], - bar: "off" - } - }); - }); - }); - - describe("isError()", () => { - - [ - ["error", true], - ["Error", true], - [2, true], - [["error"], true], - [["erRor"], true], - [[2], true], - [["error", "foo"], true], - [["eRror", "bar"], true], - [[2, "baz"], true] - ].forEach(([input, expected]) => { - - it(`should return ${expected}when passed ${input}`, () => { - const result = ConfigOps.isErrorSeverity(input); - - assert.strictEqual(result, expected); - }); - - }); - - }); - - describe("normalizeConfigGlobal", () => { - [ - ["off", "off"], - [true, "writable"], - ["true", "writable"], - [false, "readonly"], - ["false", "readonly"], - [null, "readonly"], - ["writeable", "writable"], - ["writable", "writable"], - ["readable", "readonly"], - ["readonly", "readonly"], - ["writable", "writable"] - ].forEach(([input, output]) => { - it(util.inspect(input), () => { - assert.strictEqual(ConfigOps.normalizeConfigGlobal(input), output); - }); - }); - - it("throws on other inputs", () => { - assert.throws( - () => ConfigOps.normalizeConfigGlobal("something else"), - /^'something else' is not a valid configuration for a global \(use 'readonly', 'writable', or 'off'\)$/u - ); - }); - }); -}); diff --git a/tests/lib/shared/naming.js b/tests/lib/shared/naming.js deleted file mode 100644 index ead218307b1..00000000000 --- a/tests/lib/shared/naming.js +++ /dev/null @@ -1,76 +0,0 @@ -/* - * STOP!!! DO NOT MODIFY. - * - * This file is part of the ongoing work to move the eslintrc-style config - * system into the @eslint/eslintrc package. This file needs to remain - * unchanged in order for this work to proceed. - * - * If you think you need to change this file, please contact @nzakas first. - * - * Thanks in advance for your cooperation. - */ - -/** - * @fileoverview Tests for naming util - */ -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const assert = require("chai").assert, - naming = require("../../../lib/shared/naming"); - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -describe("naming", () => { - describe("normalizePackageName()", () => { - - [ - ["foo", "eslint-config-foo"], - ["eslint-config-foo", "eslint-config-foo"], - ["@z/foo", "@z/eslint-config-foo"], - ["@z\\foo", "@z/eslint-config-foo"], - ["@z\\foo\\bar.js", "@z/eslint-config-foo/bar.js"], - ["@z/eslint-config", "@z/eslint-config"], - ["@z/eslint-config-foo", "@z/eslint-config-foo"] - ].forEach(([input, expected]) => { - it(`should return ${expected} when passed ${input}`, () => { - const result = naming.normalizePackageName(input, "eslint-config"); - - assert.strictEqual(result, expected); - }); - }); - - }); - - describe("getShorthandName()", () => { - - [ - ["foo", "foo"], - ["eslint-config-foo", "foo"], - ["@z", "@z"], - ["@z/eslint-config", "@z"], - ["@z/foo", "@z/foo"], - ["@z/eslint-config-foo", "@z/foo"] - ].forEach(([input, expected]) => { - it(`should return ${expected} when passed ${input}`, () => { - const result = naming.getShorthandName(input, "eslint-config"); - - assert.strictEqual(result, expected); - }); - }); - - }); - - describe("getNamespaceFromTerm()", () => { - it("should remove namespace when passed with namespace", () => { - const namespace = naming.getNamespaceFromTerm("@namespace/eslint-plugin-test"); - - assert.strictEqual(namespace, "@namespace/"); - }); - }); -});