@open-xchange/linter-presets 1.30.3 → 1.30.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/stylelint/index.mjs +1 -1
- package/dist/stylelint/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/stylelint/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ const messages = ruleMessages(ruleName, {
|
|
|
25
25
|
rejectedInvalid: "Invalid license header"
|
|
26
26
|
});
|
|
27
27
|
const meta = {
|
|
28
|
-
url: "https://gitlab.
|
|
28
|
+
url: "https://gitlab.com/openxchange/appsuite/documents/commons/plugins/-/blob/main/packages/linter-presets/docs/stylelint/README.md",
|
|
29
29
|
fixable: true
|
|
30
30
|
};
|
|
31
31
|
const promiseCache = /* @__PURE__ */ new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["licensePlugin"],"sources":["../../src/stylelint/rules/license-header.ts","../../src/stylelint/package-utils.ts","../../src/stylelint/index.ts"],"sourcesContent":["\nimport { readFile } from 'node:fs/promises'\nimport stylelint from 'stylelint'\n\nconst { createPlugin, utils: { ruleMessages, validateOptions, report } } = stylelint\n\n// types ======================================================================\n\ntype RuleMeta = stylelint.RuleMeta\ntype RuleFunction = stylelint.RuleBase<string, unknown>\n\n// constants ==================================================================\n\nconst ruleName = 'license-header/header'\n\nconst messages = ruleMessages(ruleName, {\n rejectedMissing: 'Missing license header',\n rejectedInvalid: 'Invalid license header',\n})\n\nconst meta: RuleMeta = {\n url: 'https://gitlab.open-xchange.com/fspd/commons/plugins/-/blob/main/packages/linter-presets/docs/stylelint/README.md',\n fixable: true,\n}\n\n// functions ==================================================================\n\nconst promiseCache = new Map<string, Promise<string>>()\n\n/**\n * Reads the license header file once per file path.\n *\n * @param path\n * The path to the license header file.\n *\n * @returns\n * A promise that will resolve with the contents of the license header file.\n */\nconst readLicenseHeaderOnce = async (path: string): Promise<string> => {\n let promise = promiseCache.get(path)\n if (!promise) {\n promise = readFile(path, 'utf-8')\n promiseCache.set(path, promise)\n }\n return await promise\n}\n\n/**\n * Implementation of the linter rule.\n *\n * @param primary\n * The path to the license header file.\n *\n * @returns\n * The callback function for the linter.\n */\nconst ruleFunc: RuleFunction = (primary) => async (root, result) => {\n\n // validate rule options\n if (!validateOptions(result, ruleName, {\n actual: primary,\n possible: path => (typeof path === 'string') && (path.length > 0),\n })) return\n\n // find the first comment in the linted file\n type Comment = Parameters<Parameters<typeof root.walkComments>[0]>[0]\n let comment: Comment | undefined\n root.walkComments(node => {\n if (node.parent === root) comment = node // must be a top-level comment\n return false // always stop iteration after first comment\n })\n\n // read the license header file\n const license = await readLicenseHeaderOnce(primary)\n\n // exit successfully if comment found and matches the license header file\n if (comment) {\n // strip block comment markers for comparison\n const stripped = license.trim().replace(/^\\/\\*|\\*\\/$/g, '').trim()\n if (comment.text === stripped) return\n }\n\n // report missing or mismatching comment\n report({\n ruleName,\n result,\n message: comment ? messages.rejectedInvalid : messages.rejectedMissing,\n node: comment ?? root,\n fix: () => { root.prepend(license) },\n })\n}\n\n// exports ====================================================================\n\nexport default createPlugin(ruleName, Object.assign(ruleFunc, { meta, ruleName, messages }))\n","\nimport type { Config, Plugin } from 'stylelint'\nimport lessPlugin from 'stylelint-less'\nimport scssPlugin from 'stylelint-scss'\nimport htmlConfig from 'stylelint-config-html'\nimport recommendedConfig from 'stylelint-config-recommended'\nimport recommendedLessConfig from 'stylelint-config-recommended-less'\nimport recommendedScssConfig from 'stylelint-config-recommended-scss'\nimport recommendedVueConfig from 'stylelint-config-recommended-vue'\nimport recommendedVueScssConfig from 'stylelint-config-recommended-vue/scss'\nimport standardConfig from 'stylelint-config-standard'\nimport standardLessConfig from 'stylelint-config-standard-less'\nimport standardScssConfig from 'stylelint-config-standard-scss'\nimport standardVueConfig from 'stylelint-config-standard-vue'\nimport standardVueScssConfig from 'stylelint-config-standard-vue/scss'\nimport stylisticPlugin from '@stylistic/stylelint-plugin'\nimport stylisticConfig from '@stylistic/stylelint-config'\nimport tailwindConfig from 'stylelint-config-tailwindcss'\n\n// constants ==================================================================\n\nconst PLUGINS: Record<string, Plugin | undefined> = {\n '@stylistic/stylelint-plugin': stylisticPlugin,\n 'stylelint-less': lessPlugin,\n 'stylelint-scss': scssPlugin,\n}\n\nconst CONFIGS: Record<string, Config | undefined> = {\n '@stylistic/stylelint-config': stylisticConfig,\n 'stylelint-config-html': htmlConfig,\n 'stylelint-config-recommended': recommendedConfig,\n 'stylelint-config-recommended-less': recommendedLessConfig,\n 'stylelint-config-recommended-scss': recommendedScssConfig,\n 'stylelint-config-recommended-vue': recommendedVueConfig,\n 'stylelint-config-recommended-vue/scss': recommendedVueScssConfig,\n 'stylelint-config-standard': standardConfig,\n 'stylelint-config-standard-less': standardLessConfig,\n 'stylelint-config-standard-scss': standardScssConfig,\n 'stylelint-config-standard-vue': standardVueConfig,\n 'stylelint-config-standard-vue/scss': standardVueScssConfig,\n 'stylelint-config-tailwindcss': tailwindConfig,\n}\n\n// functions ==================================================================\n\n/**\n * Resolves string entries in the configuration options `plugins` and `extends`\n * to imported objects.\n *\n * @param config\n * The configuration to be resolved.\n */\nfunction resolveEntries(config: Config): void {\n\n // resolve string references to plugin packages\n config.plugins &&= [config.plugins].flat().map(entry => {\n if (typeof entry !== 'string') return entry\n const resolved = PLUGINS[entry]\n if (!resolved) throw new Error(`unknown plugin package '${entry}'`)\n return resolved\n })\n\n // resolve string references to extension packages\n // @ts-expect-error -- broken types\n config.extends &&= [config.extends].flat().map(entry => {\n if (typeof entry !== 'string') return entry\n const resolved = CONFIGS[entry]\n if (!resolved) throw new Error(`unknown extension package '${entry}'`)\n // recursively resolve extensions in imported package\n return resolveConfigPackages(resolved)\n })\n}\n\n/**\n * Recursively resolves string entries in the `extends` configuration option\n * with the resolved packages. Needed to workaround broken import resolution in\n * stylelint with pnpm.\n *\n * @template ConfigT\n * The exact type of the configuration (e.g. override config with files).\n *\n * @param config\n * The configuration to be resolved.\n *\n * @returns\n * The passed configuration object with resolved extensions.\n */\nexport function resolveConfigPackages<ConfigT extends Config>(config: ConfigT): ConfigT {\n resolveEntries(config)\n config.overrides?.forEach(resolveEntries)\n return config\n}\n","\nimport type { Config } from 'stylelint'\n\nimport licensePlugin from '@/stylelint/rules/license-header.ts'\nimport { resolveConfigPackages } from '@/stylelint/package-utils.ts'\nimport { PathResolver } from '@/utils/resolver.ts'\n\n// types ======================================================================\n\n/**\n * Configuration for multiple rules.\n */\nexport type RuleRecord = NonNullable<Config['rules']>\n\n// ----------------------------------------------------------------------------\n\n/**\n * Configuration options for StyleLint code style rules.\n */\nexport interface StylisticOptions {\n\n /**\n * Default indentation size (number of space characters).\n *\n * @default 2\n */\n indent?: number\n\n /**\n * The type of the string delimiter character.\n *\n * @default 'single'\n */\n quotes?: 'single' | 'double' | 'off'\n}\n\n// ----------------------------------------------------------------------------\n\n/**\n * Configuration options for linting vue files.\n */\nexport interface VueOptions {\n\n /**\n * The language parser plugin to be used.\n *\n * @default 'css'\n */\n lang?: 'css' | 'scss'\n\n /**\n * Additional linter rules for Vue source files to be added to the global\n * configuration.\n */\n rules?: RuleRecord\n}\n\n// ----------------------------------------------------------------------------\n\n/**\n * Configuration options for linting the entire project with StyleLint.\n */\nexport interface ProjectOptions {\n\n /**\n * The URL of the project root containing the StyleLint configuration file.\n * Should usually be set to `import.meta.url`.\n */\n root: string\n\n /**\n * Glob patterns for all files to be ignored by StyleLint (the patterns must\n * match files, plain directory names are not supported).\n */\n ignores?: string[]\n\n /**\n * Path to the template file containing the license header to be used in all\n * source files. May be a path relative to the project root.\n */\n license?: string\n\n /**\n * Whether the project uses TailwindCSS. Causes to add the configuration\n * package `stylelint-config-tailwindcss`.\n */\n tailwind?: boolean\n\n /**\n * Configuration options for code style.\n */\n stylistic?: StylisticOptions\n\n /**\n * Options for linting styles in Vue files.\n */\n vue?: VueOptions\n\n /**\n * Additional linter rules to be added to the global configuration. Rule\n * names starting with `scss/` or `less/` will automatically be assigned to\n * the respective language override configuration.\n */\n rules?: RuleRecord\n}\n\n// functions ==================================================================\n\n/**\n * Generates a StyleLint configuration object targeting the source files in the\n * entire project.\n *\n * @param options\n * Plugin configuration options.\n *\n * @returns\n * The configuration object to be exported from `stylelint.config.js`.\n */\nexport function defineConfig(options: ProjectOptions): Config {\n\n const ignoreFiles: string[] = [\n 'node_modules/**/*',\n 'dist/**/*',\n 'output/**/*',\n 'coverage/**/*', // Vitest\n '.nuxt/**/*', // NuxtJS\n '.output/**/*', // NuxtJS\n ...(options.ignores ?? []),\n ]\n\n // resolve stylistic configuration options\n const stylistic: StylisticOptions = {\n indent: 2,\n quotes: 'single',\n ...options.stylistic,\n }\n\n // the resolver for relative file paths\n const resolver = new PathResolver(options.root)\n\n // custom extensions, grouped by language type\n const extensions = {\n base: [\n 'stylelint-config-standard',\n '@stylistic/stylelint-config',\n ],\n scss: [\n 'stylelint-config-standard-scss',\n ],\n less: [\n 'stylelint-config-standard-less',\n ],\n vue: [\n (options.vue?.lang === 'scss') ? 'stylelint-config-standard-vue/scss' : 'stylelint-config-standard-vue',\n ],\n } satisfies Record<string, Config['extends']>\n\n // add TailwindCSS extension if specified\n if (options.tailwind) {\n extensions.base.push('stylelint-config-tailwindcss')\n }\n\n // custom rules, grouped by language type\n const rules: Record<string, RuleRecord> = {\n base: {\n 'at-rule-empty-line-before': null,\n 'color-function-notation': ['modern', { ignore: ['with-var-inside'] }],\n 'color-hex-length': null,\n 'comment-empty-line-before': null,\n 'custom-property-empty-line-before': null,\n 'declaration-block-no-redundant-longhand-properties': [true, { ignoreShorthands: ['inset'] }], // Safari does not support 'inset'\n 'declaration-block-single-line-max-declarations': null,\n 'declaration-empty-line-before': null,\n 'function-url-no-scheme-relative': true,\n 'function-url-scheme-allowed-list': ['data'],\n 'media-feature-range-notation': 'prefix', // Safari 16.3 does not work with this notation\n 'no-descending-specificity': null,\n 'no-unknown-animations': true,\n 'rule-empty-line-before': null,\n 'shorthand-property-no-redundant-values': [true, { ignore: ['four-into-three-edge-values'] }],\n // override rules of @stylistic plugin\n '@stylistic/declaration-colon-newline-after': null,\n '@stylistic/indentation': [stylistic.indent, { ignore: ['inside-parens'] }],\n '@stylistic/max-line-length': null,\n '@stylistic/no-empty-first-line': null,\n '@stylistic/selector-list-comma-newline-after': null,\n '@stylistic/string-quotes': (stylistic.quotes === 'off') ? null : [stylistic.quotes, { avoidEscape: true }],\n },\n scss: {\n 'scss/dollar-variable-empty-line-before': null,\n 'scss/double-slash-comment-empty-line-before': null,\n },\n less: {},\n vue: {\n ...options.vue?.rules,\n },\n }\n\n // distribute custom rules by language type\n if (options.rules) {\n for (const [name, rule] of Object.entries(options.rules)) {\n const key = name.split('/')[0];\n (rules[key] ?? rules.base)[name] = rule as unknown\n }\n }\n\n // custom overrides\n const overrides: Config['overrides'] = [{\n files: ['**/*.scss'],\n extends: extensions.scss,\n rules: rules.scss,\n }, {\n files: ['**/*.less'],\n extends: extensions.less,\n rules: rules.less,\n }, {\n files: ['**/*.vue'],\n extends: extensions.vue,\n rules: rules.vue,\n }]\n\n // license header plugin\n if (options.license) {\n overrides.push({\n files: ['**/*.{css,scss,less}'], // not for Vue files\n plugins: licensePlugin,\n rules: {\n 'license-header/header': resolver.path(options.license),\n },\n })\n }\n\n return resolveConfigPackages({\n\n // ignore certain files and folders\n ignoreFiles,\n\n // check inline directives\n reportDescriptionlessDisables: null,\n reportInvalidScopeDisables: true,\n reportNeedlessDisables: true,\n reportUnscopedDisables: true,\n\n // add all extensions, rules, and overrides configured above\n extends: extensions.base,\n rules: rules.base,\n overrides,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAIA,MAAM,EAAE,cAAc,OAAO,EAAE,cAAc,iBAAiB,aAAa;AAS3E,MAAM,WAAW;AAEjB,MAAM,WAAW,aAAa,UAAU;CACtC,iBAAiB;CACjB,iBAAiB;AACnB,CAAC;AAED,MAAM,OAAiB;CACrB,KAAK;CACL,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;EACpB,OAAO,MAAM;EACb;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["licensePlugin"],"sources":["../../src/stylelint/rules/license-header.ts","../../src/stylelint/package-utils.ts","../../src/stylelint/index.ts"],"sourcesContent":["\nimport { readFile } from 'node:fs/promises'\nimport stylelint from 'stylelint'\n\nconst { createPlugin, utils: { ruleMessages, validateOptions, report } } = stylelint\n\n// types ======================================================================\n\ntype RuleMeta = stylelint.RuleMeta\ntype RuleFunction = stylelint.RuleBase<string, unknown>\n\n// constants ==================================================================\n\nconst ruleName = 'license-header/header'\n\nconst messages = ruleMessages(ruleName, {\n rejectedMissing: 'Missing license header',\n rejectedInvalid: 'Invalid license header',\n})\n\nconst meta: RuleMeta = {\n url: 'https://gitlab.com/openxchange/appsuite/documents/commons/plugins/-/blob/main/packages/linter-presets/docs/stylelint/README.md',\n fixable: true,\n}\n\n// functions ==================================================================\n\nconst promiseCache = new Map<string, Promise<string>>()\n\n/**\n * Reads the license header file once per file path.\n *\n * @param path\n * The path to the license header file.\n *\n * @returns\n * A promise that will resolve with the contents of the license header file.\n */\nconst readLicenseHeaderOnce = async (path: string): Promise<string> => {\n let promise = promiseCache.get(path)\n if (!promise) {\n promise = readFile(path, 'utf-8')\n promiseCache.set(path, promise)\n }\n return await promise\n}\n\n/**\n * Implementation of the linter rule.\n *\n * @param primary\n * The path to the license header file.\n *\n * @returns\n * The callback function for the linter.\n */\nconst ruleFunc: RuleFunction = (primary) => async (root, result) => {\n\n // validate rule options\n if (!validateOptions(result, ruleName, {\n actual: primary,\n possible: path => (typeof path === 'string') && (path.length > 0),\n })) return\n\n // find the first comment in the linted file\n type Comment = Parameters<Parameters<typeof root.walkComments>[0]>[0]\n let comment: Comment | undefined\n root.walkComments(node => {\n if (node.parent === root) comment = node // must be a top-level comment\n return false // always stop iteration after first comment\n })\n\n // read the license header file\n const license = await readLicenseHeaderOnce(primary)\n\n // exit successfully if comment found and matches the license header file\n if (comment) {\n // strip block comment markers for comparison\n const stripped = license.trim().replace(/^\\/\\*|\\*\\/$/g, '').trim()\n if (comment.text === stripped) return\n }\n\n // report missing or mismatching comment\n report({\n ruleName,\n result,\n message: comment ? messages.rejectedInvalid : messages.rejectedMissing,\n node: comment ?? root,\n fix: () => { root.prepend(license) },\n })\n}\n\n// exports ====================================================================\n\nexport default createPlugin(ruleName, Object.assign(ruleFunc, { meta, ruleName, messages }))\n","\nimport type { Config, Plugin } from 'stylelint'\nimport lessPlugin from 'stylelint-less'\nimport scssPlugin from 'stylelint-scss'\nimport htmlConfig from 'stylelint-config-html'\nimport recommendedConfig from 'stylelint-config-recommended'\nimport recommendedLessConfig from 'stylelint-config-recommended-less'\nimport recommendedScssConfig from 'stylelint-config-recommended-scss'\nimport recommendedVueConfig from 'stylelint-config-recommended-vue'\nimport recommendedVueScssConfig from 'stylelint-config-recommended-vue/scss'\nimport standardConfig from 'stylelint-config-standard'\nimport standardLessConfig from 'stylelint-config-standard-less'\nimport standardScssConfig from 'stylelint-config-standard-scss'\nimport standardVueConfig from 'stylelint-config-standard-vue'\nimport standardVueScssConfig from 'stylelint-config-standard-vue/scss'\nimport stylisticPlugin from '@stylistic/stylelint-plugin'\nimport stylisticConfig from '@stylistic/stylelint-config'\nimport tailwindConfig from 'stylelint-config-tailwindcss'\n\n// constants ==================================================================\n\nconst PLUGINS: Record<string, Plugin | undefined> = {\n '@stylistic/stylelint-plugin': stylisticPlugin,\n 'stylelint-less': lessPlugin,\n 'stylelint-scss': scssPlugin,\n}\n\nconst CONFIGS: Record<string, Config | undefined> = {\n '@stylistic/stylelint-config': stylisticConfig,\n 'stylelint-config-html': htmlConfig,\n 'stylelint-config-recommended': recommendedConfig,\n 'stylelint-config-recommended-less': recommendedLessConfig,\n 'stylelint-config-recommended-scss': recommendedScssConfig,\n 'stylelint-config-recommended-vue': recommendedVueConfig,\n 'stylelint-config-recommended-vue/scss': recommendedVueScssConfig,\n 'stylelint-config-standard': standardConfig,\n 'stylelint-config-standard-less': standardLessConfig,\n 'stylelint-config-standard-scss': standardScssConfig,\n 'stylelint-config-standard-vue': standardVueConfig,\n 'stylelint-config-standard-vue/scss': standardVueScssConfig,\n 'stylelint-config-tailwindcss': tailwindConfig,\n}\n\n// functions ==================================================================\n\n/**\n * Resolves string entries in the configuration options `plugins` and `extends`\n * to imported objects.\n *\n * @param config\n * The configuration to be resolved.\n */\nfunction resolveEntries(config: Config): void {\n\n // resolve string references to plugin packages\n config.plugins &&= [config.plugins].flat().map(entry => {\n if (typeof entry !== 'string') return entry\n const resolved = PLUGINS[entry]\n if (!resolved) throw new Error(`unknown plugin package '${entry}'`)\n return resolved\n })\n\n // resolve string references to extension packages\n // @ts-expect-error -- broken types\n config.extends &&= [config.extends].flat().map(entry => {\n if (typeof entry !== 'string') return entry\n const resolved = CONFIGS[entry]\n if (!resolved) throw new Error(`unknown extension package '${entry}'`)\n // recursively resolve extensions in imported package\n return resolveConfigPackages(resolved)\n })\n}\n\n/**\n * Recursively resolves string entries in the `extends` configuration option\n * with the resolved packages. Needed to workaround broken import resolution in\n * stylelint with pnpm.\n *\n * @template ConfigT\n * The exact type of the configuration (e.g. override config with files).\n *\n * @param config\n * The configuration to be resolved.\n *\n * @returns\n * The passed configuration object with resolved extensions.\n */\nexport function resolveConfigPackages<ConfigT extends Config>(config: ConfigT): ConfigT {\n resolveEntries(config)\n config.overrides?.forEach(resolveEntries)\n return config\n}\n","\nimport type { Config } from 'stylelint'\n\nimport licensePlugin from '@/stylelint/rules/license-header.ts'\nimport { resolveConfigPackages } from '@/stylelint/package-utils.ts'\nimport { PathResolver } from '@/utils/resolver.ts'\n\n// types ======================================================================\n\n/**\n * Configuration for multiple rules.\n */\nexport type RuleRecord = NonNullable<Config['rules']>\n\n// ----------------------------------------------------------------------------\n\n/**\n * Configuration options for StyleLint code style rules.\n */\nexport interface StylisticOptions {\n\n /**\n * Default indentation size (number of space characters).\n *\n * @default 2\n */\n indent?: number\n\n /**\n * The type of the string delimiter character.\n *\n * @default 'single'\n */\n quotes?: 'single' | 'double' | 'off'\n}\n\n// ----------------------------------------------------------------------------\n\n/**\n * Configuration options for linting vue files.\n */\nexport interface VueOptions {\n\n /**\n * The language parser plugin to be used.\n *\n * @default 'css'\n */\n lang?: 'css' | 'scss'\n\n /**\n * Additional linter rules for Vue source files to be added to the global\n * configuration.\n */\n rules?: RuleRecord\n}\n\n// ----------------------------------------------------------------------------\n\n/**\n * Configuration options for linting the entire project with StyleLint.\n */\nexport interface ProjectOptions {\n\n /**\n * The URL of the project root containing the StyleLint configuration file.\n * Should usually be set to `import.meta.url`.\n */\n root: string\n\n /**\n * Glob patterns for all files to be ignored by StyleLint (the patterns must\n * match files, plain directory names are not supported).\n */\n ignores?: string[]\n\n /**\n * Path to the template file containing the license header to be used in all\n * source files. May be a path relative to the project root.\n */\n license?: string\n\n /**\n * Whether the project uses TailwindCSS. Causes to add the configuration\n * package `stylelint-config-tailwindcss`.\n */\n tailwind?: boolean\n\n /**\n * Configuration options for code style.\n */\n stylistic?: StylisticOptions\n\n /**\n * Options for linting styles in Vue files.\n */\n vue?: VueOptions\n\n /**\n * Additional linter rules to be added to the global configuration. Rule\n * names starting with `scss/` or `less/` will automatically be assigned to\n * the respective language override configuration.\n */\n rules?: RuleRecord\n}\n\n// functions ==================================================================\n\n/**\n * Generates a StyleLint configuration object targeting the source files in the\n * entire project.\n *\n * @param options\n * Plugin configuration options.\n *\n * @returns\n * The configuration object to be exported from `stylelint.config.js`.\n */\nexport function defineConfig(options: ProjectOptions): Config {\n\n const ignoreFiles: string[] = [\n 'node_modules/**/*',\n 'dist/**/*',\n 'output/**/*',\n 'coverage/**/*', // Vitest\n '.nuxt/**/*', // NuxtJS\n '.output/**/*', // NuxtJS\n ...(options.ignores ?? []),\n ]\n\n // resolve stylistic configuration options\n const stylistic: StylisticOptions = {\n indent: 2,\n quotes: 'single',\n ...options.stylistic,\n }\n\n // the resolver for relative file paths\n const resolver = new PathResolver(options.root)\n\n // custom extensions, grouped by language type\n const extensions = {\n base: [\n 'stylelint-config-standard',\n '@stylistic/stylelint-config',\n ],\n scss: [\n 'stylelint-config-standard-scss',\n ],\n less: [\n 'stylelint-config-standard-less',\n ],\n vue: [\n (options.vue?.lang === 'scss') ? 'stylelint-config-standard-vue/scss' : 'stylelint-config-standard-vue',\n ],\n } satisfies Record<string, Config['extends']>\n\n // add TailwindCSS extension if specified\n if (options.tailwind) {\n extensions.base.push('stylelint-config-tailwindcss')\n }\n\n // custom rules, grouped by language type\n const rules: Record<string, RuleRecord> = {\n base: {\n 'at-rule-empty-line-before': null,\n 'color-function-notation': ['modern', { ignore: ['with-var-inside'] }],\n 'color-hex-length': null,\n 'comment-empty-line-before': null,\n 'custom-property-empty-line-before': null,\n 'declaration-block-no-redundant-longhand-properties': [true, { ignoreShorthands: ['inset'] }], // Safari does not support 'inset'\n 'declaration-block-single-line-max-declarations': null,\n 'declaration-empty-line-before': null,\n 'function-url-no-scheme-relative': true,\n 'function-url-scheme-allowed-list': ['data'],\n 'media-feature-range-notation': 'prefix', // Safari 16.3 does not work with this notation\n 'no-descending-specificity': null,\n 'no-unknown-animations': true,\n 'rule-empty-line-before': null,\n 'shorthand-property-no-redundant-values': [true, { ignore: ['four-into-three-edge-values'] }],\n // override rules of @stylistic plugin\n '@stylistic/declaration-colon-newline-after': null,\n '@stylistic/indentation': [stylistic.indent, { ignore: ['inside-parens'] }],\n '@stylistic/max-line-length': null,\n '@stylistic/no-empty-first-line': null,\n '@stylistic/selector-list-comma-newline-after': null,\n '@stylistic/string-quotes': (stylistic.quotes === 'off') ? null : [stylistic.quotes, { avoidEscape: true }],\n },\n scss: {\n 'scss/dollar-variable-empty-line-before': null,\n 'scss/double-slash-comment-empty-line-before': null,\n },\n less: {},\n vue: {\n ...options.vue?.rules,\n },\n }\n\n // distribute custom rules by language type\n if (options.rules) {\n for (const [name, rule] of Object.entries(options.rules)) {\n const key = name.split('/')[0];\n (rules[key] ?? rules.base)[name] = rule as unknown\n }\n }\n\n // custom overrides\n const overrides: Config['overrides'] = [{\n files: ['**/*.scss'],\n extends: extensions.scss,\n rules: rules.scss,\n }, {\n files: ['**/*.less'],\n extends: extensions.less,\n rules: rules.less,\n }, {\n files: ['**/*.vue'],\n extends: extensions.vue,\n rules: rules.vue,\n }]\n\n // license header plugin\n if (options.license) {\n overrides.push({\n files: ['**/*.{css,scss,less}'], // not for Vue files\n plugins: licensePlugin,\n rules: {\n 'license-header/header': resolver.path(options.license),\n },\n })\n }\n\n return resolveConfigPackages({\n\n // ignore certain files and folders\n ignoreFiles,\n\n // check inline directives\n reportDescriptionlessDisables: null,\n reportInvalidScopeDisables: true,\n reportNeedlessDisables: true,\n reportUnscopedDisables: true,\n\n // add all extensions, rules, and overrides configured above\n extends: extensions.base,\n rules: rules.base,\n overrides,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAIA,MAAM,EAAE,cAAc,OAAO,EAAE,cAAc,iBAAiB,aAAa;AAS3E,MAAM,WAAW;AAEjB,MAAM,WAAW,aAAa,UAAU;CACtC,iBAAiB;CACjB,iBAAiB;AACnB,CAAC;AAED,MAAM,OAAiB;CACrB,KAAK;CACL,SAAS;AACX;AAIA,MAAM,+BAAe,IAAI,IAA6B;;;;;;;;;;AAWtD,MAAM,wBAAwB,OAAO,SAAkC;CACrE,IAAI,UAAU,aAAa,IAAI,IAAI;CACnC,IAAI,CAAC,SAAS;EACZ,UAAU,SAAS,MAAM,OAAO;EAChC,aAAa,IAAI,MAAM,OAAO;CAChC;CACA,OAAO,MAAM;AACf;;;;;;;;;;AAWA,MAAM,YAA0B,YAAY,OAAO,MAAM,WAAW;CAGlE,IAAI,CAAC,gBAAgB,QAAQ,UAAU;EACrC,QAAQ;EACR,WAAU,SAAS,OAAO,SAAS,YAAc,KAAK,SAAS;CACjE,CAAC,GAAG;CAIJ,IAAI;CACJ,KAAK,cAAa,SAAQ;EACxB,IAAI,KAAK,WAAW,MAAM,UAAU;EACpC,OAAO;CACT,CAAC;CAGD,MAAM,UAAU,MA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AAG,QAAQ,KAAK,MAClB;CACF;CAGA,IAAI,QAAQ,OACV,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,GAAG;EACxD,MAAM,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC;EAC5B,CAAC,MAAM,QAAQ,MAAM,KAAA,CAAM,QAAQ;CACrC;CAIF,MAAM,YAAiC;EAAC;GACtC,OAAO,CAAC,WAAW;GACnB,SAAS,WAAW;GACpB,OAAO,MAAM;EACf;EAAG;GACD,OAAO,CAAC,WAAW;GACnB,SAAS,WAAW;GACpB,OAAO,MAAM;EACf;EAAG;GACD,OAAO,CAAC,UAAU;GAClB,SAAS,WAAW;GACpB,OAAO,MAAM;EACf;CAAC;CAGD,IAAI,QAAQ,SACV,UAAU,KAAK;EACb,OAAO,CAAC,sBAAsB;EAC9B,SAASA;EACT,OAAO,EACL,yBAAyB,SAAS,KAAK,QAAQ,OAAO,EACxD;CACF,CAAC;CAGH,OAAO,sBAAsB;EAG3B;EAGA,+BAA+B;EAC/B,4BAA4B;EAC5B,wBAAwB;EACxB,wBAAwB;EAGxB,SAAS,WAAW;EACpB,OAAO,MAAM;EACb;CACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/linter-presets",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.4",
|
|
4
4
|
"description": "Configuration presets for ESLint and StyleLint",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://gitlab.
|
|
7
|
+
"url": "git+https://gitlab.com/openxchange/appsuite/documents/commons/plugins.git",
|
|
8
8
|
"directory": "packages/linter-presets"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@jest/globals": "^30.5.1",
|
|
88
|
-
"@open-xchange/tsconfig": "^0.2.
|
|
88
|
+
"@open-xchange/tsconfig": "^0.2.3",
|
|
89
89
|
"@types/confusing-browser-globals": "^1.0.3",
|
|
90
90
|
"@types/react": "^19.2.18",
|
|
91
91
|
"@typescript-eslint/utils": "^8.70.0",
|