UNPKG

@manuth/eslint-plugin-typescript

Version:

A set of personal eslint-rulesets for TypeScript-projects

188 lines 6.98 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.configs = exports.flatConfigs = exports.PluginName = exports.GenerateConfiguration = exports.PresetName = void 0; const js_1 = __importDefault(require("@eslint/js")); // eslint-disable-next-line import-x/no-rename-default const eslint_plugin_1 = __importDefault(require("@stylistic/eslint-plugin")); const eslint_plugin_import_x_1 = require("eslint-plugin-import-x"); const typescript_eslint_1 = require("typescript-eslint"); const GenerateConfiguration_cjs_1 = require("./Configuration/GenerateConfiguration.cjs"); const PresetName_cjs_1 = require("./PresetName.cjs"); const rule_configs_cjs_1 = require("./rule-configs.cjs"); var PresetName_cjs_2 = require("./PresetName.cjs"); Object.defineProperty(exports, "PresetName", { enumerable: true, get: function () { return PresetName_cjs_2.PresetName; } }); var GenerateConfiguration_cjs_2 = require("./Configuration/GenerateConfiguration.cjs"); Object.defineProperty(exports, "GenerateConfiguration", { enumerable: true, get: function () { return GenerateConfiguration_cjs_2.GenerateConfiguration; } }); /** * The name of the plugin. */ exports.PluginName = "@manuth/typescript"; let flatConfigCache = new Map(); let cache = new Map(); /** * Converts the specified {@linkcode pattern} for the use with the flat configuration interface. * * @param pattern * The pattern set to convert. * * @returns * A representation of the pattern which can be used for the use with the flat configuration interface. */ function ConvertPattern(pattern) { return pattern.map((pattern) => `**/${pattern}`); } /** * Loads the flat config with the specified name. * * @param config * The definition of the configuration. * * @returns * The flat config for the specified definition. */ function LoadFlatConfig(config) { var _a, _b; let result = flatConfigCache.get(config); if (!result) { let name = `${exports.PluginName}/${config.name}`; result = [ { name, files: [ "**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}" ], rules: config.config }, ...(_b = (_a = config.overrides) === null || _a === void 0 ? void 0 : _a.map((override) => { return Object.assign(Object.assign({ name: `${name}/${override.name}`, files: ConvertPattern(override.include) }, override.exclude ? { ignores: ConvertPattern(override.exclude) } : {}), { rules: override.config }); })) !== null && _b !== void 0 ? _b : [] ]; flatConfigCache.set(config, result); return result; } else { return result; } } /** * Loads the preset with the specified {@linkcode presetName}. * * @param presetName * The name of the preset to load. * * @returns * The preset with the specified {@linkcode presetName}. */ function LoadPreset(presetName) { if (!cache.has(presetName)) { let weak; let typeChecking; switch (presetName) { case PresetName_cjs_1.PresetName.Recommended: case PresetName_cjs_1.PresetName.RecommendedWithTypeChecking: weak = false; break; default: weak = true; break; } switch (presetName) { case PresetName_cjs_1.PresetName.RecommendedWithTypeChecking: case PresetName_cjs_1.PresetName.WeakWithTypeChecking: typeChecking = true; break; default: typeChecking = false; break; } cache.set(presetName, (0, GenerateConfiguration_cjs_1.GenerateConfiguration)(weak, typeChecking)); } return cache.get(presetName); } const configBase = { get common() { return [ js_1.default.configs.recommended, eslint_plugin_1.default.configs["disable-legacy"], eslint_plugin_1.default.configs["recommended-flat"], eslint_plugin_import_x_1.flatConfigs.typescript, ...typescript_eslint_1.configs.recommended, { plugins: { ["@stylistic" /* ESLintPlugin.Stylistic */]: eslint_plugin_1.default, ["@typescript-eslint" /* ESLintPlugin.TypeScriptESLint */]: require("@typescript-eslint/eslint-plugin"), ["@eslint-community/eslint-comments" /* ESLintPlugin.ESLintComments */]: require("@eslint-community/eslint-plugin-eslint-comments"), ["import" /* ESLintPlugin.Import */]: require("eslint-plugin-import"), ["import-x" /* ESLintPlugin.ImportX */]: require("eslint-plugin-import-x"), ["jsdoc" /* ESLintPlugin.JSDoc */]: require("eslint-plugin-jsdoc"), ["n" /* ESLintPlugin.Node */]: require("eslint-plugin-n") } } ]; }, get typeChecking() { return [ { languageOptions: { parser: require("@typescript-eslint/parser") } } ]; } }; /** * Provides configurations for the flat configuration interface of `eslint`. */ exports.flatConfigs = { get recommended() { return [ ...exports.flatConfigs.weak, ...LoadFlatConfig(rule_configs_cjs_1.recommended) ]; }, get recommendedWithTypeChecking() { return [ ...exports.flatConfigs.weakWithTypeChecking, ...exports.flatConfigs.recommended, ...LoadFlatConfig(rule_configs_cjs_1.recommendedWithTypeChecking) ]; }, get weak() { return [ ...configBase.common, ...LoadFlatConfig(rule_configs_cjs_1.weak) ]; }, get weakWithTypeChecking() { return [ ...exports.flatConfigs.weak, ...configBase.typeChecking, ...LoadFlatConfig(rule_configs_cjs_1.weakWithTypeChecking) ]; } }; /** * Provides configurations for the eslintrc configuration interface of `eslint`. */ exports.configs = { get [PresetName_cjs_1.PresetName.Recommended]() { return LoadPreset(PresetName_cjs_1.PresetName.Recommended); }, get [PresetName_cjs_1.PresetName.RecommendedWithTypeChecking]() { return LoadPreset(PresetName_cjs_1.PresetName.RecommendedWithTypeChecking); }, get [PresetName_cjs_1.PresetName.Weak]() { return LoadPreset(PresetName_cjs_1.PresetName.Weak); }, get [PresetName_cjs_1.PresetName.WeakWithTypeChecking]() { return LoadPreset(PresetName_cjs_1.PresetName.WeakWithTypeChecking); } }; //# sourceMappingURL=index.cjs.map