update
This commit is contained in:
@@ -0,0 +1,565 @@
|
||||
// @ts-self-types="./index.d.ts"
|
||||
/**
|
||||
* @fileoverview defineConfig helper
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Type Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("eslint").Linter.Config} Config */
|
||||
/** @typedef {import("eslint").Linter.LegacyConfig} LegacyConfig */
|
||||
/** @typedef {import("eslint").ESLint.Plugin} Plugin */
|
||||
/** @typedef {import("eslint").Linter.RuleEntry} RuleEntry */
|
||||
/** @typedef {import("./types.ts").ExtendsElement} ExtendsElement */
|
||||
/** @typedef {import("./types.ts").SimpleExtendsElement} SimpleExtendsElement */
|
||||
/** @typedef {import("./types.ts").ConfigWithExtends} ConfigWithExtends */
|
||||
/** @typedef {import("./types.ts").InfiniteArray<Config>} InfiniteConfigArray */
|
||||
/** @typedef {import("./types.ts").ConfigWithExtendsArray} ConfigWithExtendsArray */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const eslintrcKeys = [
|
||||
"env",
|
||||
"extends",
|
||||
"globals",
|
||||
"ignorePatterns",
|
||||
"noInlineConfig",
|
||||
"overrides",
|
||||
"parser",
|
||||
"parserOptions",
|
||||
"reportUnusedDisableDirectives",
|
||||
"root",
|
||||
];
|
||||
|
||||
const allowedGlobalIgnoreKeys = new Set(["ignores", "name"]);
|
||||
|
||||
/**
|
||||
* Gets the name of a config object.
|
||||
* @param {Config} config The config object.
|
||||
* @param {string} indexPath The index path of the config object.
|
||||
* @return {string} The name of the config object.
|
||||
*/
|
||||
function getConfigName(config, indexPath) {
|
||||
if (config.name) {
|
||||
return config.name;
|
||||
}
|
||||
|
||||
return `UserConfig${indexPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of an extension.
|
||||
* @param {SimpleExtendsElement} extension The extension.
|
||||
* @param {string} indexPath The index of the extension.
|
||||
* @return {string} The name of the extension.
|
||||
*/
|
||||
function getExtensionName(extension, indexPath) {
|
||||
if (typeof extension === "string") {
|
||||
return extension;
|
||||
}
|
||||
|
||||
if (extension.name) {
|
||||
return extension.name;
|
||||
}
|
||||
|
||||
return `ExtendedConfig${indexPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a config object is a legacy config.
|
||||
* @param {Config|LegacyConfig} config The config object to check.
|
||||
* @return {config is LegacyConfig} `true` if the config object is a legacy config.
|
||||
*/
|
||||
function isLegacyConfig(config) {
|
||||
for (const key of eslintrcKeys) {
|
||||
if (key in config) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a config object is a global ignores config.
|
||||
* @param {Config} config The config object to check.
|
||||
* @return {boolean} `true` if the config object is a global ignores config.
|
||||
*/
|
||||
function isGlobalIgnores(config) {
|
||||
return Object.keys(config).every(key => allowedGlobalIgnoreKeys.has(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a plugin member ID (rule, processor, etc.) and returns
|
||||
* the namespace and member name.
|
||||
* @param {string} id The ID to parse.
|
||||
* @returns {{namespace:string, name:string}} The namespace and member name.
|
||||
*/
|
||||
function getPluginMember(id) {
|
||||
const firstSlashIndex = id.indexOf("/");
|
||||
|
||||
if (firstSlashIndex === -1) {
|
||||
return { namespace: "", name: id };
|
||||
}
|
||||
|
||||
let namespace = id.slice(0, firstSlashIndex);
|
||||
|
||||
/*
|
||||
* Special cases:
|
||||
* 1. The namespace is `@`, that means it's referring to the
|
||||
* core plugin so `@` is the full namespace.
|
||||
* 2. The namespace starts with `@`, that means it's referring to
|
||||
* an npm scoped package. That means the namespace is the scope
|
||||
* and the package name (i.e., `@eslint/core`).
|
||||
*/
|
||||
if (namespace[0] === "@" && namespace !== "@") {
|
||||
const secondSlashIndex = id.indexOf("/", firstSlashIndex + 1);
|
||||
if (secondSlashIndex !== -1) {
|
||||
namespace = id.slice(0, secondSlashIndex);
|
||||
return { namespace, name: id.slice(secondSlashIndex + 1) };
|
||||
}
|
||||
}
|
||||
|
||||
const name = id.slice(firstSlashIndex + 1);
|
||||
|
||||
return { namespace, name };
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the plugin config by replacing the namespace with the plugin namespace.
|
||||
* @param {string} userNamespace The namespace of the plugin.
|
||||
* @param {Plugin} plugin The plugin config object.
|
||||
* @param {Config} config The config object to normalize.
|
||||
* @return {Config} The normalized config object.
|
||||
*/
|
||||
function normalizePluginConfig(userNamespace, plugin, config) {
|
||||
// @ts-ignore -- ESLint types aren't updated yet
|
||||
const pluginNamespace = plugin.meta?.namespace;
|
||||
|
||||
// don't do anything if the plugin doesn't have a namespace or rules
|
||||
if (
|
||||
!pluginNamespace ||
|
||||
pluginNamespace === userNamespace ||
|
||||
(!config.rules && !config.processor && !config.language)
|
||||
) {
|
||||
return config;
|
||||
}
|
||||
|
||||
const result = { ...config };
|
||||
|
||||
// update the rules
|
||||
if (result.rules) {
|
||||
const ruleIds = Object.keys(result.rules);
|
||||
|
||||
/** @type {Record<string,RuleEntry|undefined>} */
|
||||
const newRules = {};
|
||||
|
||||
for (let i = 0; i < ruleIds.length; i++) {
|
||||
const ruleId = ruleIds[i];
|
||||
const { namespace: ruleNamespace, name: ruleName } =
|
||||
getPluginMember(ruleId);
|
||||
|
||||
if (ruleNamespace === pluginNamespace) {
|
||||
newRules[`${userNamespace}/${ruleName}`] = result.rules[ruleId];
|
||||
} else {
|
||||
newRules[ruleId] = result.rules[ruleId];
|
||||
}
|
||||
}
|
||||
|
||||
result.rules = newRules;
|
||||
}
|
||||
|
||||
// update the processor
|
||||
|
||||
if (typeof result.processor === "string") {
|
||||
const { namespace: processorNamespace, name: processorName } =
|
||||
getPluginMember(result.processor);
|
||||
|
||||
if (processorNamespace) {
|
||||
if (processorNamespace === pluginNamespace) {
|
||||
result.processor = `${userNamespace}/${processorName}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the language
|
||||
if (typeof result.language === "string") {
|
||||
const { namespace: languageNamespace, name: languageName } =
|
||||
getPluginMember(result.language);
|
||||
|
||||
if (languageNamespace === pluginNamespace) {
|
||||
result.language = `${userNamespace}/${languageName}`;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deeply normalizes a plugin config, traversing recursively into an arrays.
|
||||
* @param {string} userPluginNamespace The namespace of the plugin.
|
||||
* @param {Plugin} plugin The plugin object.
|
||||
* @param {Config|LegacyConfig|(Config|LegacyConfig)[]} pluginConfig The plugin config to normalize.
|
||||
* @param {string} pluginConfigName The name of the plugin config.
|
||||
* @return {InfiniteConfigArray} The normalized plugin config.
|
||||
*/
|
||||
function deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
pluginConfig,
|
||||
pluginConfigName,
|
||||
) {
|
||||
// if it's an array then it's definitely a new config
|
||||
if (Array.isArray(pluginConfig)) {
|
||||
return pluginConfig.map(pluginSubConfig =>
|
||||
deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
pluginSubConfig,
|
||||
pluginConfigName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// if it's a legacy config, throw an error
|
||||
if (isLegacyConfig(pluginConfig)) {
|
||||
throw new TypeError(
|
||||
`Plugin config "${pluginConfigName}" is an eslintrc config and cannot be used in this context.`,
|
||||
);
|
||||
}
|
||||
|
||||
return normalizePluginConfig(userPluginNamespace, plugin, pluginConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a plugin config by name in the given config.
|
||||
* @param {Config} config The config object.
|
||||
* @param {string} pluginConfigName The name of the plugin config.
|
||||
* @return {InfiniteConfigArray} The plugin config.
|
||||
*/
|
||||
function findPluginConfig(config, pluginConfigName) {
|
||||
const { namespace: userPluginNamespace, name: configName } =
|
||||
getPluginMember(pluginConfigName);
|
||||
const plugin = config.plugins?.[userPluginNamespace];
|
||||
|
||||
if (!plugin) {
|
||||
throw new TypeError(`Plugin "${userPluginNamespace}" not found.`);
|
||||
}
|
||||
|
||||
const directConfig = plugin.configs?.[configName];
|
||||
if (directConfig) {
|
||||
// Arrays are always flat configs, and non-legacy configs can be used directly
|
||||
if (Array.isArray(directConfig) || !isLegacyConfig(directConfig)) {
|
||||
return deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
directConfig,
|
||||
pluginConfigName,
|
||||
);
|
||||
}
|
||||
|
||||
// If it's a legacy config, look for the flat version
|
||||
const flatConfig = plugin.configs?.[`flat/${configName}`];
|
||||
|
||||
if (
|
||||
flatConfig &&
|
||||
(Array.isArray(flatConfig) || !isLegacyConfig(flatConfig))
|
||||
) {
|
||||
return deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
flatConfig,
|
||||
pluginConfigName,
|
||||
);
|
||||
}
|
||||
|
||||
throw new TypeError(
|
||||
`Plugin config "${configName}" in plugin "${userPluginNamespace}" is an eslintrc config and cannot be used in this context.`,
|
||||
);
|
||||
}
|
||||
|
||||
throw new TypeError(
|
||||
`Plugin config "${configName}" not found in plugin "${userPluginNamespace}".`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens an array while keeping track of the index path.
|
||||
* @param {any[]} configList The array to traverse.
|
||||
* @param {string} indexPath The index path of the value in a multidimensional array.
|
||||
* @return {IterableIterator<{indexPath:string, value:any}>} The flattened list of values.
|
||||
*/
|
||||
function* flatTraverse(configList, indexPath = "") {
|
||||
for (let i = 0; i < configList.length; i++) {
|
||||
const newIndexPath = indexPath ? `${indexPath}[${i}]` : `[${i}]`;
|
||||
|
||||
// if it's an array then traverse it as well
|
||||
if (Array.isArray(configList[i])) {
|
||||
yield* flatTraverse(configList[i], newIndexPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
yield { indexPath: newIndexPath, value: configList[i] };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends a list of config files by creating every combination of base and extension files.
|
||||
* @param {(string|string[])[]} [baseFiles] The base files.
|
||||
* @param {(string|string[])[]} [extensionFiles] The extension files.
|
||||
* @return {(string|string[])[]} The extended files.
|
||||
*/
|
||||
function extendConfigFiles(baseFiles = [], extensionFiles = []) {
|
||||
if (!extensionFiles.length) {
|
||||
return baseFiles.concat();
|
||||
}
|
||||
|
||||
if (!baseFiles.length) {
|
||||
return extensionFiles.concat();
|
||||
}
|
||||
|
||||
/** @type {(string|string[])[]} */
|
||||
const result = [];
|
||||
|
||||
for (const baseFile of baseFiles) {
|
||||
for (const extensionFile of extensionFiles) {
|
||||
/*
|
||||
* Each entry can be a string or array of strings. The end result
|
||||
* needs to be an array of strings, so we need to be sure to include
|
||||
* all of the items when there's an array.
|
||||
*/
|
||||
|
||||
const entry = [];
|
||||
|
||||
if (Array.isArray(baseFile)) {
|
||||
entry.push(...baseFile);
|
||||
} else {
|
||||
entry.push(baseFile);
|
||||
}
|
||||
|
||||
if (Array.isArray(extensionFile)) {
|
||||
entry.push(...extensionFile);
|
||||
} else {
|
||||
entry.push(extensionFile);
|
||||
}
|
||||
|
||||
result.push(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends a config object with another config object.
|
||||
* @param {Config} baseConfig The base config object.
|
||||
* @param {string} baseConfigName The name of the base config object.
|
||||
* @param {Config} extension The extension config object.
|
||||
* @param {string} extensionName The index of the extension config object.
|
||||
* @return {Config} The extended config object.
|
||||
*/
|
||||
function extendConfig(baseConfig, baseConfigName, extension, extensionName) {
|
||||
const result = { ...extension };
|
||||
|
||||
// for global ignores there is no further work to be done, we just keep everything
|
||||
if (!isGlobalIgnores(extension)) {
|
||||
// for files we need to create every combination of base and extension files
|
||||
if (baseConfig.files) {
|
||||
result.files = extendConfigFiles(baseConfig.files, extension.files);
|
||||
}
|
||||
|
||||
// for ignores we just concatenation the extension ignores onto the base ignores
|
||||
if (baseConfig.ignores) {
|
||||
result.ignores = baseConfig.ignores.concat(extension.ignores ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
result.name = `${baseConfigName} > ${extensionName}`;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a list of extends elements.
|
||||
* @param {ConfigWithExtends} config The config object.
|
||||
* @param {WeakMap<Config, string>} configNames The map of config objects to their names.
|
||||
* @return {Config[]} The flattened list of config objects.
|
||||
*/
|
||||
function processExtends(config, configNames) {
|
||||
if (!config.extends) {
|
||||
return [config];
|
||||
}
|
||||
|
||||
if (!Array.isArray(config.extends)) {
|
||||
throw new TypeError("The `extends` property must be an array.");
|
||||
}
|
||||
|
||||
const {
|
||||
/** @type {Config[]} */
|
||||
extends: extendsList,
|
||||
|
||||
/** @type {Config} */
|
||||
...configObject
|
||||
} = config;
|
||||
|
||||
const extensionNames = new WeakMap();
|
||||
|
||||
// replace strings with the actual configs
|
||||
const objectExtends = extendsList.map(extendsElement => {
|
||||
if (typeof extendsElement === "string") {
|
||||
const pluginConfig = findPluginConfig(config, extendsElement);
|
||||
|
||||
// assign names
|
||||
if (Array.isArray(pluginConfig)) {
|
||||
pluginConfig.forEach((pluginConfigElement, index) => {
|
||||
extensionNames.set(
|
||||
pluginConfigElement,
|
||||
`${extendsElement}[${index}]`,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
extensionNames.set(pluginConfig, extendsElement);
|
||||
}
|
||||
|
||||
return pluginConfig;
|
||||
}
|
||||
|
||||
return /** @type {Config} */ (extendsElement);
|
||||
});
|
||||
|
||||
const result = [];
|
||||
|
||||
for (const { indexPath, value: extendsElement } of flatTraverse(
|
||||
objectExtends,
|
||||
)) {
|
||||
const extension = /** @type {Config} */ (extendsElement);
|
||||
|
||||
if ("extends" in extension) {
|
||||
throw new TypeError("Nested 'extends' is not allowed.");
|
||||
}
|
||||
|
||||
const baseConfigName = /** @type {string} */ (configNames.get(config));
|
||||
const extensionName =
|
||||
extensionNames.get(extendsElement) ??
|
||||
getExtensionName(extendsElement, indexPath);
|
||||
|
||||
result.push(
|
||||
extendConfig(
|
||||
configObject,
|
||||
baseConfigName,
|
||||
extension,
|
||||
extensionName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the base config object has only `ignores` and `extends`, then
|
||||
* removing `extends` turns it into a global ignores, which is not what
|
||||
* we want. So we need to check if the base config object is a global ignores
|
||||
* and if so, we don't add it to the array.
|
||||
*
|
||||
* (The other option would be to add a `files` entry, but that would result
|
||||
* in a config that didn't actually do anything because there are no
|
||||
* other keys in the config.)
|
||||
*/
|
||||
if (!isGlobalIgnores(configObject)) {
|
||||
result.push(configObject);
|
||||
}
|
||||
|
||||
return result.flat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a list of config objects and arrays.
|
||||
* @param {ConfigWithExtends[]} configList The list of config objects and arrays.
|
||||
* @param {WeakMap<Config, string>} configNames The map of config objects to their names.
|
||||
* @return {Config[]} The flattened list of config objects.
|
||||
*/
|
||||
function processConfigList(configList, configNames) {
|
||||
return configList.flatMap(config => processExtends(config, configNames));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Helper function to define a config array.
|
||||
* @param {ConfigWithExtendsArray} args The arguments to the function.
|
||||
* @returns {Config[]} The config array.
|
||||
*/
|
||||
function defineConfig(...args) {
|
||||
const configNames = new WeakMap();
|
||||
const configs = [];
|
||||
|
||||
if (args.length === 0) {
|
||||
throw new TypeError("Expected one or more arguments.");
|
||||
}
|
||||
|
||||
// first flatten the list of configs and get the names
|
||||
for (const { indexPath, value } of flatTraverse(args)) {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new TypeError(
|
||||
`Expected an object but received ${String(value)}.`,
|
||||
);
|
||||
}
|
||||
|
||||
const config = /** @type {ConfigWithExtends} */ (value);
|
||||
|
||||
// save config name for easy reference later
|
||||
configNames.set(config, getConfigName(config, indexPath));
|
||||
configs.push(config);
|
||||
}
|
||||
|
||||
return processConfigList(configs, configNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @fileoverview Global ignores helper function.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Type Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
let globalIgnoreCount = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a global ignores config with the given patterns.
|
||||
* @param {string[]} ignorePatterns The ignore patterns.
|
||||
* @param {string} [name] The name of the global ignores config.
|
||||
* @returns {Config} The global ignores config.
|
||||
*/
|
||||
function globalIgnores(ignorePatterns, name) {
|
||||
if (!Array.isArray(ignorePatterns)) {
|
||||
throw new TypeError("ignorePatterns must be an array");
|
||||
}
|
||||
|
||||
if (ignorePatterns.length === 0) {
|
||||
throw new TypeError("ignorePatterns must contain at least one pattern");
|
||||
}
|
||||
|
||||
const id = globalIgnoreCount++;
|
||||
|
||||
return {
|
||||
name: name || `globalIgnores ${id}`,
|
||||
ignores: ignorePatterns,
|
||||
};
|
||||
}
|
||||
|
||||
export { defineConfig, globalIgnores };
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","2":"C L M G N O P"},C:{"1":"0 1 2 3 4 5 6 7 8 9 PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"nC LC qC rC","33":"J"},D:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC"},E:{"1":"J PB K D E F A B C L M G tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"sC SC"},F:{"1":"0 1 2 3 4 5 6 7 8 G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","2":"F B C 4C 5C 6C 7C FC kC 8C","132":"GC"},G:{"2":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"2":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD","2":"J"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"rD","2":"qD"}},B:2,C:"CSS resize property",D:true};
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import Ref from './Ref.js';
|
||||
|
||||
describe('Ref', () => {
|
||||
it('returns proper reference for given num and gen', () => {
|
||||
const num = 1;
|
||||
const gen = 2;
|
||||
const ref = new Ref({ num, gen });
|
||||
expect(ref.toString()).toBe('1R2');
|
||||
});
|
||||
|
||||
it('returns proper reference for given num and gen when gen = 0', () => {
|
||||
const num = 1;
|
||||
const gen = 0;
|
||||
const ref = new Ref({ num, gen });
|
||||
expect(ref.toString()).toBe('1R');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "caniuse-lite",
|
||||
"version": "1.0.30001710",
|
||||
"description": "A smaller version of caniuse-db, with only the essentials!",
|
||||
"main": "dist/unpacker/index.js",
|
||||
"files": [
|
||||
"data",
|
||||
"dist"
|
||||
],
|
||||
"keywords": [
|
||||
"support"
|
||||
],
|
||||
"author": {
|
||||
"name": "Ben Briggs",
|
||||
"email": "beneb.info@gmail.com",
|
||||
"url": "http://beneb.info"
|
||||
},
|
||||
"repository": "browserslist/caniuse-lite",
|
||||
"funding": [
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/browserslist"
|
||||
},
|
||||
{
|
||||
"type": "tidelift",
|
||||
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ai"
|
||||
}
|
||||
],
|
||||
"license": "CC-BY-4.0"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,307 @@
|
||||
/**
|
||||
* @fileoverview Rule to check empty newline after "var" statement
|
||||
* @author Gopal Venkatesan
|
||||
* @deprecated in ESLint v4.0.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Require or disallow an empty line after variable declarations",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/newline-after-var",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
enum: ["never", "always"],
|
||||
},
|
||||
],
|
||||
fixable: "whitespace",
|
||||
messages: {
|
||||
expected: "Expected blank line after variable declarations.",
|
||||
unexpected: "Unexpected blank line after variable declarations.",
|
||||
},
|
||||
|
||||
deprecated: {
|
||||
message: "The rule was replaced with a more general rule.",
|
||||
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
|
||||
deprecatedSince: "4.0.0",
|
||||
availableUntil: null,
|
||||
replacedBy: [
|
||||
{
|
||||
message: "The new rule moved to a plugin.",
|
||||
url: "https://eslint.org/docs/latest/rules/padding-line-between-statements#examples",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin-js",
|
||||
url: "https://eslint.style/packages/js",
|
||||
},
|
||||
rule: {
|
||||
name: "padding-line-between-statements",
|
||||
url: "https://eslint.style/rules/js/padding-line-between-statements",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
// Default `mode` to "always".
|
||||
const mode = context.options[0] === "never" ? "never" : "always";
|
||||
|
||||
// Cache starting and ending line numbers of comments for faster lookup
|
||||
const commentEndLine = sourceCode
|
||||
.getAllComments()
|
||||
.reduce((result, token) => {
|
||||
result[token.loc.start.line] = token.loc.end.line;
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets a token from the given node to compare line to the next statement.
|
||||
*
|
||||
* In general, the token is the last token of the node. However, the token is the second last token if the following conditions satisfy.
|
||||
*
|
||||
* - The last token is semicolon.
|
||||
* - The semicolon is on a different line from the previous token of the semicolon.
|
||||
*
|
||||
* This behavior would address semicolon-less style code. e.g.:
|
||||
*
|
||||
* var foo = 1
|
||||
*
|
||||
* ;(a || b).doSomething()
|
||||
* @param {ASTNode} node The node to get.
|
||||
* @returns {Token} The token to compare line to the next statement.
|
||||
*/
|
||||
function getLastToken(node) {
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
|
||||
if (lastToken.type === "Punctuator" && lastToken.value === ";") {
|
||||
const prevToken = sourceCode.getTokenBefore(lastToken);
|
||||
|
||||
if (prevToken.loc.end.line !== lastToken.loc.start.line) {
|
||||
return prevToken;
|
||||
}
|
||||
}
|
||||
|
||||
return lastToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided keyword is a variable declaration
|
||||
* @private
|
||||
* @param {string} keyword keyword to test
|
||||
* @returns {boolean} True if `keyword` is a type of var
|
||||
*/
|
||||
function isVar(keyword) {
|
||||
return (
|
||||
keyword === "var" || keyword === "let" || keyword === "const"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided keyword is a variant of for specifiers
|
||||
* @private
|
||||
* @param {string} keyword keyword to test
|
||||
* @returns {boolean} True if `keyword` is a variant of for specifier
|
||||
*/
|
||||
function isForTypeSpecifier(keyword) {
|
||||
return (
|
||||
keyword === "ForStatement" ||
|
||||
keyword === "ForInStatement" ||
|
||||
keyword === "ForOfStatement"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided keyword is an export specifiers
|
||||
* @private
|
||||
* @param {string} nodeType nodeType to test
|
||||
* @returns {boolean} True if `nodeType` is an export specifier
|
||||
*/
|
||||
function isExportSpecifier(nodeType) {
|
||||
return (
|
||||
nodeType === "ExportNamedDeclaration" ||
|
||||
nodeType === "ExportSpecifier" ||
|
||||
nodeType === "ExportDefaultDeclaration" ||
|
||||
nodeType === "ExportAllDeclaration"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided node is the last of their parent block.
|
||||
* @private
|
||||
* @param {ASTNode} node node to test
|
||||
* @returns {boolean} True if `node` is last of their parent block.
|
||||
*/
|
||||
function isLastNode(node) {
|
||||
const token = sourceCode.getTokenAfter(node);
|
||||
|
||||
return (
|
||||
!token || (token.type === "Punctuator" && token.value === "}")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last line of a group of consecutive comments
|
||||
* @param {number} commentStartLine The starting line of the group
|
||||
* @returns {number} The number of the last comment line of the group
|
||||
*/
|
||||
function getLastCommentLineOfBlock(commentStartLine) {
|
||||
const currentCommentEnd = commentEndLine[commentStartLine];
|
||||
|
||||
return commentEndLine[currentCommentEnd + 1]
|
||||
? getLastCommentLineOfBlock(currentCommentEnd + 1)
|
||||
: currentCommentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a token starts more than one line after a comment ends
|
||||
* @param {token} token The token being checked
|
||||
* @param {integer} commentStartLine The line number on which the comment starts
|
||||
* @returns {boolean} True if `token` does not start immediately after a comment
|
||||
*/
|
||||
function hasBlankLineAfterComment(token, commentStartLine) {
|
||||
return (
|
||||
token.loc.start.line >
|
||||
getLastCommentLineOfBlock(commentStartLine) + 1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that a blank line exists after a variable declaration when mode is
|
||||
* set to "always", or checks that there is no blank line when mode is set
|
||||
* to "never"
|
||||
* @private
|
||||
* @param {ASTNode} node `VariableDeclaration` node to test
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkForBlankLine(node) {
|
||||
/*
|
||||
* lastToken is the last token on the node's line. It will usually also be the last token of the node, but it will
|
||||
* sometimes be second-last if there is a semicolon on a different line.
|
||||
*/
|
||||
const lastToken = getLastToken(node),
|
||||
/*
|
||||
* If lastToken is the last token of the node, nextToken should be the token after the node. Otherwise, nextToken
|
||||
* is the last token of the node.
|
||||
*/
|
||||
nextToken =
|
||||
lastToken === sourceCode.getLastToken(node)
|
||||
? sourceCode.getTokenAfter(node)
|
||||
: sourceCode.getLastToken(node),
|
||||
nextLineNum = lastToken.loc.end.line + 1;
|
||||
|
||||
// Ignore if there is no following statement
|
||||
if (!nextToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if parent of node is a for variant
|
||||
if (isForTypeSpecifier(node.parent.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if parent of node is an export specifier
|
||||
if (isExportSpecifier(node.parent.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some coding styles use multiple `var` statements, so do nothing if
|
||||
* the next token is a `var` statement.
|
||||
*/
|
||||
if (nextToken.type === "Keyword" && isVar(nextToken.value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if it is last statement in a block
|
||||
if (isLastNode(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Next statement is not a `var`...
|
||||
const noNextLineToken = nextToken.loc.start.line > nextLineNum;
|
||||
const hasNextLineComment =
|
||||
typeof commentEndLine[nextLineNum] !== "undefined";
|
||||
|
||||
if (mode === "never" && noNextLineToken && !hasNextLineComment) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "unexpected",
|
||||
fix(fixer) {
|
||||
const linesBetween = sourceCode
|
||||
.getText()
|
||||
.slice(lastToken.range[1], nextToken.range[0])
|
||||
.split(astUtils.LINEBREAK_MATCHER);
|
||||
|
||||
return fixer.replaceTextRange(
|
||||
[lastToken.range[1], nextToken.range[0]],
|
||||
`${linesBetween.slice(0, -1).join("")}\n${linesBetween.at(-1)}`,
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Token on the next line, or comment without blank line
|
||||
if (
|
||||
mode === "always" &&
|
||||
(!noNextLineToken ||
|
||||
(hasNextLineComment &&
|
||||
!hasBlankLineAfterComment(nextToken, nextLineNum)))
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "expected",
|
||||
fix(fixer) {
|
||||
if (
|
||||
(noNextLineToken
|
||||
? getLastCommentLineOfBlock(nextLineNum)
|
||||
: lastToken.loc.end.line) ===
|
||||
nextToken.loc.start.line
|
||||
) {
|
||||
return fixer.insertTextBefore(nextToken, "\n\n");
|
||||
}
|
||||
|
||||
return fixer.insertTextBeforeRange(
|
||||
[
|
||||
nextToken.range[0] - nextToken.loc.start.column,
|
||||
nextToken.range[1],
|
||||
],
|
||||
"\n",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
VariableDeclaration: checkForBlankLine,
|
||||
};
|
||||
},
|
||||
};
|
||||
Binary file not shown.
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* @fileoverview enforce `for` loop update clause moving the counter in the right direction.(for-direction)
|
||||
* @author Aladdin-ADD<hh_2013@foxmail.com>
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const { getStaticValue } = require("@eslint-community/eslint-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Enforce `for` loop update clause moving the counter in the right direction",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/for-direction",
|
||||
},
|
||||
|
||||
fixable: null,
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
incorrectDirection:
|
||||
"The update clause in this loop moves the variable in the wrong direction.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const { sourceCode } = context;
|
||||
|
||||
/**
|
||||
* report an error.
|
||||
* @param {ASTNode} node the node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function report(node) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "incorrectDirection",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* check the right side of the assignment
|
||||
* @param {ASTNode} update UpdateExpression to check
|
||||
* @param {int} dir expected direction that could either be turned around or invalidated
|
||||
* @returns {int} return dir, the negated dir, or zero if the counter does not change or the direction is not clear
|
||||
*/
|
||||
function getRightDirection(update, dir) {
|
||||
const staticValue = getStaticValue(
|
||||
update.right,
|
||||
sourceCode.getScope(update),
|
||||
);
|
||||
|
||||
if (
|
||||
staticValue &&
|
||||
["bigint", "boolean", "number"].includes(
|
||||
typeof staticValue.value,
|
||||
)
|
||||
) {
|
||||
const sign = Math.sign(Number(staticValue.value)) || 0; // convert NaN to 0
|
||||
|
||||
return dir * sign;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* check UpdateExpression add/sub the counter
|
||||
* @param {ASTNode} update UpdateExpression to check
|
||||
* @param {string} counter variable name to check
|
||||
* @returns {int} if add return 1, if sub return -1, if nochange, return 0
|
||||
*/
|
||||
function getUpdateDirection(update, counter) {
|
||||
if (
|
||||
update.argument.type === "Identifier" &&
|
||||
update.argument.name === counter
|
||||
) {
|
||||
if (update.operator === "++") {
|
||||
return 1;
|
||||
}
|
||||
if (update.operator === "--") {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* check AssignmentExpression add/sub the counter
|
||||
* @param {ASTNode} update AssignmentExpression to check
|
||||
* @param {string} counter variable name to check
|
||||
* @returns {int} if add return 1, if sub return -1, if nochange, return 0
|
||||
*/
|
||||
function getAssignmentDirection(update, counter) {
|
||||
if (update.left.name === counter) {
|
||||
if (update.operator === "+=") {
|
||||
return getRightDirection(update, 1);
|
||||
}
|
||||
if (update.operator === "-=") {
|
||||
return getRightDirection(update, -1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return {
|
||||
ForStatement(node) {
|
||||
if (
|
||||
node.test &&
|
||||
node.test.type === "BinaryExpression" &&
|
||||
node.update
|
||||
) {
|
||||
for (const counterPosition of ["left", "right"]) {
|
||||
if (node.test[counterPosition].type !== "Identifier") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const counter = node.test[counterPosition].name;
|
||||
const operator = node.test.operator;
|
||||
const update = node.update;
|
||||
|
||||
let wrongDirection;
|
||||
|
||||
if (operator === "<" || operator === "<=") {
|
||||
wrongDirection =
|
||||
counterPosition === "left" ? -1 : 1;
|
||||
} else if (operator === ">" || operator === ">=") {
|
||||
wrongDirection =
|
||||
counterPosition === "left" ? 1 : -1;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (update.type === "UpdateExpression") {
|
||||
if (
|
||||
getUpdateDirection(update, counter) ===
|
||||
wrongDirection
|
||||
) {
|
||||
report(node);
|
||||
}
|
||||
} else if (
|
||||
update.type === "AssignmentExpression" &&
|
||||
getAssignmentDirection(update, counter) ===
|
||||
wrongDirection
|
||||
) {
|
||||
report(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = validateNode;
|
||||
var _validate = require("../validators/validate.js");
|
||||
var _index = require("../index.js");
|
||||
function validateNode(node) {
|
||||
if (node == null || typeof node !== "object") return;
|
||||
const fields = _index.NODE_FIELDS[node.type];
|
||||
if (!fields) return;
|
||||
const keys = _index.BUILDER_KEYS[node.type];
|
||||
for (const key of keys) {
|
||||
const field = fields[key];
|
||||
if (field != null) (0, _validate.validateInternal)(field, node, key, node[key]);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=validateNode.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"125":0.00279,"135":0.00279,"136":0.01116,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 126 127 128 129 130 131 132 133 134 137 138 139 140 3.5 3.6"},D:{"109":0.01116,"124":0.00837,"129":0.00837,"130":0.00279,"131":0.01116,"132":0.00558,"133":0.09765,"134":0.12555,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 110 111 112 113 114 115 116 117 118 119 120 121 122 123 125 126 127 128 135 136 137 138"},F:{"116":0.00558,"117":0.01395,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"109":0.00837,"132":0.00279,"133":0.03348,"134":0.07254,_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131"},E:{_:"0 4 5 6 7 8 9 10 11 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 12.1","13.1":0.00837,"14.1":0.01395,"15.1":0.03906,"15.2-15.3":0.00558,"15.4":0.0279,"15.5":0.10044,"15.6":1.07415,"16.0":0.02232,"16.1":0.16461,"16.2":0.23994,"16.3":0.46593,"16.4":0.10881,"16.5":0.19809,"16.6":2.06181,"17.0":0.06417,"17.1":1.6461,"17.2":0.11718,"17.3":0.13113,"17.4":0.30969,"17.5":0.48825,"17.6":1.89999,"18.0":0.16182,"18.1":0.90396,"18.2":0.36828,"18.3":16.2378,"18.4":0.07812},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.01437,"5.0-5.1":0,"6.0-6.1":0.04312,"7.0-7.1":0.02875,"8.1-8.4":0,"9.0-9.2":0.02156,"9.3":0.10062,"10.0-10.2":0.00719,"10.3":0.1653,"11.0-11.2":0.76181,"11.3-11.4":0.05031,"12.0-12.1":0.02875,"12.2-12.5":0.71151,"13.0-13.1":0.01437,"13.2":0.02156,"13.3":0.02875,"13.4-13.7":0.10062,"14.0-14.4":0.25154,"14.5-14.8":0.30185,"15.0-15.1":0.1653,"15.2-15.3":0.1653,"15.4":0.20123,"15.5":0.22998,"15.6-15.8":2.83165,"16.0":0.40247,"16.1":0.8265,"16.2":0.43122,"16.3":0.74744,"16.4":0.1653,"16.5":0.30904,"16.6-16.7":3.3563,"17.0":0.20123,"17.1":0.35935,"17.2":0.2731,"17.3":0.38091,"17.4":0.76181,"17.5":1.69612,"17.6-17.7":4.92305,"18.0":1.37989,"18.1":4.51339,"18.2":2.01953,"18.3":42.20883,"18.4":0.62526},P:{"27":0.03605,_:"4 20 21 22 23 24 25 26 5.0-5.4 6.2-6.4 7.2-7.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0"},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0},K:{"0":0,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.00721},Q:{_:"14.9"},O:{_:"0"},H:{"0":0},L:{"0":0.18583}};
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* @fileoverview Require or disallow newline at the end of files
|
||||
* @author Nodeca Team <https://github.com/nodeca>
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "10.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin-js",
|
||||
url: "https://eslint.style/packages/js",
|
||||
},
|
||||
rule: {
|
||||
name: "eol-last",
|
||||
url: "https://eslint.style/rules/js/eol-last",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description: "Require or disallow newline at the end of files",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/eol-last",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
|
||||
schema: [
|
||||
{
|
||||
enum: ["always", "never", "unix", "windows"],
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
missing: "Newline required at end of file but not found.",
|
||||
unexpected: "Newline not allowed at end of file.",
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
Program: function checkBadEOF(node) {
|
||||
const sourceCode = context.sourceCode,
|
||||
src = sourceCode.getText(),
|
||||
lastLine = sourceCode.lines.at(-1),
|
||||
location = {
|
||||
column: lastLine.length,
|
||||
line: sourceCode.lines.length,
|
||||
},
|
||||
LF = "\n",
|
||||
CRLF = `\r${LF}`,
|
||||
endsWithNewline = src.endsWith(LF);
|
||||
|
||||
/*
|
||||
* Empty source is always valid: No content in file so we don't
|
||||
* need to lint for a newline on the last line of content.
|
||||
*/
|
||||
if (!src.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
let mode = context.options[0] || "always",
|
||||
appendCRLF = false;
|
||||
|
||||
if (mode === "unix") {
|
||||
// `"unix"` should behave exactly as `"always"`
|
||||
mode = "always";
|
||||
}
|
||||
if (mode === "windows") {
|
||||
// `"windows"` should behave exactly as `"always"`, but append CRLF in the fixer for backwards compatibility
|
||||
mode = "always";
|
||||
appendCRLF = true;
|
||||
}
|
||||
if (mode === "always" && !endsWithNewline) {
|
||||
// File is not newline-terminated, but should be
|
||||
context.report({
|
||||
node,
|
||||
loc: location,
|
||||
messageId: "missing",
|
||||
fix(fixer) {
|
||||
return fixer.insertTextAfterRange(
|
||||
[0, src.length],
|
||||
appendCRLF ? CRLF : LF,
|
||||
);
|
||||
},
|
||||
});
|
||||
} else if (mode === "never" && endsWithNewline) {
|
||||
const secondLastLine = sourceCode.lines.at(-2);
|
||||
|
||||
// File is newline-terminated, but shouldn't be
|
||||
context.report({
|
||||
node,
|
||||
loc: {
|
||||
start: {
|
||||
line: sourceCode.lines.length - 1,
|
||||
column: secondLastLine.length,
|
||||
},
|
||||
end: { line: sourceCode.lines.length, column: 0 },
|
||||
},
|
||||
messageId: "unexpected",
|
||||
fix(fixer) {
|
||||
const finalEOLs = /(?:\r?\n)+$/u,
|
||||
match = finalEOLs.exec(sourceCode.text),
|
||||
start = match.index,
|
||||
end = sourceCode.text.length;
|
||||
|
||||
return fixer.replaceTextRange([start, end], "");
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
'use strict'
|
||||
|
||||
let Warning = require('./warning')
|
||||
|
||||
class Result {
|
||||
get content() {
|
||||
return this.css
|
||||
}
|
||||
|
||||
constructor(processor, root, opts) {
|
||||
this.processor = processor
|
||||
this.messages = []
|
||||
this.root = root
|
||||
this.opts = opts
|
||||
this.css = undefined
|
||||
this.map = undefined
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.css
|
||||
}
|
||||
|
||||
warn(text, opts = {}) {
|
||||
if (!opts.plugin) {
|
||||
if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
|
||||
opts.plugin = this.lastPlugin.postcssPlugin
|
||||
}
|
||||
}
|
||||
|
||||
let warning = new Warning(text, opts)
|
||||
this.messages.push(warning)
|
||||
|
||||
return warning
|
||||
}
|
||||
|
||||
warnings() {
|
||||
return this.messages.filter(i => i.type === 'warning')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Result
|
||||
Result.default = Result
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"88":0.0037,"115":0.09628,"122":0.0037,"128":0.0037,"132":0.0037,"133":0.04073,"135":0.13701,"136":0.47769,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 116 117 118 119 120 121 123 124 125 126 127 129 130 131 134 137 138 139 140 3.5 3.6"},D:{"38":0.0037,"39":0.0037,"40":0.0037,"41":0.00741,"43":0.0037,"44":0.00741,"45":0.0037,"46":0.0037,"47":0.0037,"48":0.0037,"50":0.00741,"51":0.0037,"52":0.0037,"53":0.04073,"54":0.0037,"55":0.0037,"58":0.0037,"59":0.0037,"62":0.1222,"63":0.0037,"69":0.00741,"73":0.01481,"74":0.00741,"75":0.00741,"79":0.05184,"80":0.0037,"81":0.0037,"87":0.04444,"89":0.01481,"90":0.00741,"91":0.04073,"92":0.0037,"94":0.01852,"95":0.0037,"97":0.01111,"99":0.0037,"100":0.01111,"103":0.04444,"105":0.0037,"108":0.05925,"109":0.95908,"110":0.04073,"111":0.04444,"112":0.0037,"115":0.00741,"116":0.19996,"119":0.03333,"120":0.0037,"121":0.05184,"122":0.05925,"123":0.01111,"124":0.02962,"125":0.02592,"126":0.04814,"127":0.00741,"128":0.04814,"129":0.02592,"130":0.02222,"131":0.18515,"132":0.60359,"133":6.16179,"134":11.13862,"135":0.0037,"136":0.0037,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 42 49 56 57 60 61 64 65 66 67 68 70 71 72 76 77 78 83 84 85 86 88 93 96 98 101 102 104 106 107 113 114 117 118 137 138"},F:{"87":0.00741,"95":0.0037,"102":0.00741,"108":0.00741,"110":0.00741,"116":0.29994,"117":0.39992,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 88 89 90 91 92 93 94 96 97 98 99 100 101 103 104 105 106 107 109 111 112 113 114 115 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6","12.1":0.0037},B:{"18":0.0037,"92":0.0037,"93":0.00741,"105":0.0037,"109":0.05925,"114":0.00741,"116":0.0037,"125":0.0037,"127":0.0037,"128":0.0037,"130":0.00741,"131":0.05184,"132":0.07776,"133":1.90705,"134":4.76206,_:"12 13 14 15 16 17 79 80 81 83 84 85 86 87 88 89 90 91 94 95 96 97 98 99 100 101 102 103 104 106 107 108 110 111 112 113 115 117 118 119 120 121 122 123 124 126 129"},E:{"14":0.04073,_:"0 4 5 6 7 8 9 10 11 12 13 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 12.1 15.1 15.5","13.1":0.02592,"14.1":0.02222,"15.2-15.3":0.00741,"15.4":0.0037,"15.6":0.16293,"16.0":0.05555,"16.1":0.12961,"16.2":0.0037,"16.3":0.06665,"16.4":0.00741,"16.5":0.04444,"16.6":0.25921,"17.0":0.01852,"17.1":0.29624,"17.2":0.02222,"17.3":0.06295,"17.4":0.06665,"17.5":0.21848,"17.6":0.75541,"18.0":0.10739,"18.1":0.1185,"18.2":0.09998,"18.3":1.83299,"18.4":0.05184},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00412,"5.0-5.1":0,"6.0-6.1":0.01235,"7.0-7.1":0.00823,"8.1-8.4":0,"9.0-9.2":0.00618,"9.3":0.02882,"10.0-10.2":0.00206,"10.3":0.04735,"11.0-11.2":0.2182,"11.3-11.4":0.01441,"12.0-12.1":0.00823,"12.2-12.5":0.20379,"13.0-13.1":0.00412,"13.2":0.00618,"13.3":0.00823,"13.4-13.7":0.02882,"14.0-14.4":0.07205,"14.5-14.8":0.08646,"15.0-15.1":0.04735,"15.2-15.3":0.04735,"15.4":0.05764,"15.5":0.06587,"15.6-15.8":0.81104,"16.0":0.11528,"16.1":0.23673,"16.2":0.12351,"16.3":0.21408,"16.4":0.04735,"16.5":0.08852,"16.6-16.7":0.96131,"17.0":0.05764,"17.1":0.10292,"17.2":0.07822,"17.3":0.1091,"17.4":0.2182,"17.5":0.4858,"17.6-17.7":1.41007,"18.0":0.39523,"18.1":1.29273,"18.2":0.57844,"18.3":12.08951,"18.4":0.17909},P:{"4":0.54265,"21":0.03322,"22":0.02215,"24":0.05537,"25":0.03322,"26":0.12182,"27":4.82846,_:"20 23 5.0-5.4 8.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0","6.2-6.4":0.02215,"7.2-7.4":0.03322,"9.2":0.0443},I:{"0":0.00628,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0.00001},K:{"0":0.15113,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.12594},Q:{_:"14.9"},O:{"0":0.05038},H:{"0":0},L:{"0":39.53631}};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"C L M G N O P","33":"0 9 Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"1":"0 9 lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB qC rC"},D:{"16":"J PB K D E F A B C L M G N O P","33":"0 1 2 3 4 5 6 7 8 9 QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC"},E:{"1":"VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"J PB sC SC tC","33":"K D E F A B C L M G uC vC wC TC FC GC xC yC zC UC"},F:{"2":"F B C 4C 5C 6C 7C FC kC 8C GC","33":"0 1 2 3 4 5 6 7 8 G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z"},G:{"1":"VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","16":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC"},H:{"2":"WD"},I:{"16":"LC J XD YD ZD aD lC bD cD","33":"I"},J:{"16":"D A"},K:{"2":"A B C FC kC GC","33":"H"},L:{"16":"I"},M:{"1":"EC"},N:{"16":"A B"},O:{"16":"HC"},P:{"16":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"33":"oD"},R:{"16":"pD"},S:{"1":"qD rD"}},B:4,C:"CSS print-color-adjust",D:true};
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as React from 'react'
|
||||
|
||||
export const matchContext = React.createContext<string | undefined>(undefined)
|
||||
|
||||
// N.B. this only exists so we can conditionally call useContext on it when we are not interested in the nearest match
|
||||
export const dummyMatchContext = React.createContext<string | undefined>(
|
||||
undefined,
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
# strip-json-comments [](https://travis-ci.com/github/sindresorhus/strip-json-comments)
|
||||
|
||||
> Strip comments from JSON. Lets you use comments in your JSON files!
|
||||
|
||||
This is now possible:
|
||||
|
||||
```js
|
||||
{
|
||||
// Rainbows
|
||||
"unicorn": /* ❤ */ "cake"
|
||||
}
|
||||
```
|
||||
|
||||
It will replace single-line comments `//` and multi-line comments `/**/` with whitespace. This allows JSON error positions to remain as close as possible to the original source.
|
||||
|
||||
Also available as a [Gulp](https://github.com/sindresorhus/gulp-strip-json-comments)/[Grunt](https://github.com/sindresorhus/grunt-strip-json-comments)/[Broccoli](https://github.com/sindresorhus/broccoli-strip-json-comments) plugin.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install strip-json-comments
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const json = `{
|
||||
// Rainbows
|
||||
"unicorn": /* ❤ */ "cake"
|
||||
}`;
|
||||
|
||||
JSON.parse(stripJsonComments(json));
|
||||
//=> {unicorn: 'cake'}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### stripJsonComments(jsonString, options?)
|
||||
|
||||
#### jsonString
|
||||
|
||||
Type: `string`
|
||||
|
||||
Accepts a string with JSON and returns a string without comments.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### whitespace
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Replace comments with whitespace instead of stripping them entirely.
|
||||
|
||||
## Benchmark
|
||||
|
||||
```
|
||||
$ npm run bench
|
||||
```
|
||||
|
||||
## Related
|
||||
|
||||
- [strip-json-comments-cli](https://github.com/sindresorhus/strip-json-comments-cli) - CLI for this module
|
||||
- [strip-css-comments](https://github.com/sindresorhus/strip-css-comments) - Strip comments from CSS
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-strip-json-comments?utm_source=npm-strip-json-comments&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
@@ -0,0 +1,23 @@
|
||||
const UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
|
||||
const UUID_PARSE = /^[0-9A-Fa-f\-]{36}/;
|
||||
//RFC 4122
|
||||
const handler = {
|
||||
scheme: "urn:uuid",
|
||||
parse: function (urnComponents, options) {
|
||||
const uuidComponents = urnComponents;
|
||||
uuidComponents.uuid = uuidComponents.nss;
|
||||
uuidComponents.nss = undefined;
|
||||
if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
|
||||
uuidComponents.error = uuidComponents.error || "UUID is not valid.";
|
||||
}
|
||||
return uuidComponents;
|
||||
},
|
||||
serialize: function (uuidComponents, options) {
|
||||
const urnComponents = uuidComponents;
|
||||
//normalize UUID
|
||||
urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
|
||||
return urnComponents;
|
||||
},
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=urn-uuid.js.map
|
||||
Reference in New Issue
Block a user