@open-xchange/linter-presets 1.31.0 → 1.31.2

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.
@@ -1,6 +1,6 @@
1
1
  import { dirname } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- //#region src/utils/resolver.ts
3
+ // src/utils/resolver.ts
4
4
  /**
5
5
  * A resolver for file paths relative to a base URL.
6
6
  */
@@ -33,7 +33,6 @@ var PathResolver = class {
33
33
  return fileURLToPath(new URL(file, this.#url));
34
34
  }
35
35
  };
36
- //#endregion
37
36
  export { PathResolver as t };
38
37
 
39
- //# sourceMappingURL=resolver-CKKbaGEf.mjs.map
38
+ //# sourceMappingURL=resolver-COtuVv5w.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolver-CKKbaGEf.mjs","names":[],"sources":["../src/utils/resolver.ts"],"sourcesContent":["\nimport { dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n// class PathResolver =========================================================\n\n/**\n * A resolver for file paths relative to a base URL.\n */\nexport class PathResolver {\n\n readonly #url: string\n readonly #root: string\n\n constructor(url: string) {\n this.#url = url\n this.#root = dirname(fileURLToPath(url))\n }\n\n /**\n * Returns the directory path of the URL passed to the constructor.\n *\n * @returns\n * The directory path of the URL passed to the constructor.\n */\n get root(): string {\n return this.#root\n }\n\n /**\n * Converts a file path relative to 'root' to an absolute file path.\n *\n * @param file\n * The file path to be converted.\n *\n * @returns\n * The absolute file path.\n */\n path(file: string): string {\n return fileURLToPath(new URL(file, this.#url))\n }\n}\n"],"mappings":";;;;;;AASA,IAAa,eAAb,MAA0B;CAExB;CACA;CAEA,YAAY,KAAa;EACvB,KAAK,OAAO;EACZ,KAAK,QAAQ,QAAQ,cAAc,GAAG,CAAC;CACzC;;;;;;;CAQA,IAAI,OAAe;EACjB,OAAO,KAAK;CACd;;;;;;;;;;CAWA,KAAK,MAAsB;EACzB,OAAO,cAAc,IAAI,IAAI,MAAM,KAAK,IAAI,CAAC;CAC/C;AACF"}
1
+ {"version":3,"file":"resolver-COtuVv5w.mjs","names":[],"sources":["../src/utils/resolver.ts"],"sourcesContent":["\nimport { dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n// class PathResolver =========================================================\n\n/**\n * A resolver for file paths relative to a base URL.\n */\nexport class PathResolver {\n\n readonly #url: string\n readonly #root: string\n\n constructor(url: string) {\n this.#url = url\n this.#root = dirname(fileURLToPath(url))\n }\n\n /**\n * Returns the directory path of the URL passed to the constructor.\n *\n * @returns\n * The directory path of the URL passed to the constructor.\n */\n get root(): string {\n return this.#root\n }\n\n /**\n * Converts a file path relative to 'root' to an absolute file path.\n *\n * @param file\n * The file path to be converted.\n *\n * @returns\n * The absolute file path.\n */\n path(file: string): string {\n return fileURLToPath(new URL(file, this.#url))\n }\n}\n"],"mappings":";;;;;;AASA,IAAa,eAAb,MAA0B;CAExB;CACA;CAEA,YAAY,KAAa;EACvB,KAAK,OAAO;EACZ,KAAK,QAAQ,QAAQ,cAAc,GAAG,CAAC;CACzC;;;;;;;CAQA,IAAI,OAAe;EACjB,OAAO,KAAK;CACd;;;;;;;;;;CAWA,KAAK,MAAsB;EACzB,OAAO,cAAc,IAAI,IAAI,MAAM,KAAK,IAAI,CAAC;CAC/C;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { Config } from "stylelint";
2
- //#region src/stylelint/index.d.ts
3
2
  /**
4
3
  * Configuration for multiple rules.
5
4
  */
@@ -89,5 +88,4 @@ export interface ProjectOptions {
89
88
  * file (e.g. `stylelint.config.ts`).
90
89
  */
91
90
  export declare function defineConfig(options: ProjectOptions): Config;
92
- //#endregion
93
91
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/stylelint/index.ts"],"mappings":";;;;;YAYY,aAAa,YAAY;;;;iBAOpB;;;;;;EAOf;;;;;;;EAQA;;;;;iBAQe;;;;;;EAOf;;;;;EAMA,QAAQ;;;;;iBAQO;;;;;EAMf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;EAKA,YAAY;;;;EAKZ,MAAM;;;;;;EAON,QAAQ;;;;;;;;;;;;;wBAgBM,aAAa,SAAS,iBAAiB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/stylelint/index.ts"],"mappings":";;;;YAYY,aAAa,YAAY;;;;iBAOpB;;;;;;EAOf;;;;;;;EAQA;;;;;iBAQe;;;;;;EAOf;;;;;EAMA,QAAQ;;;;;iBAQO;;;;;EAMf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;EAKA,YAAY;;;;EAKZ,MAAM;;;;;;EAON,QAAQ;;;;;;;;;;;;;wBAgBM,aAAa,SAAS,iBAAiB"}
@@ -1,8 +1,8 @@
1
- import { t as PathResolver } from "../resolver-CKKbaGEf.mjs";
1
+ import { t as PathResolver } from "../resolver-COtuVv5w.mjs";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import stylelint from "stylelint";
5
- //#region src/stylelint/rules/license-header.ts
5
+ // src/stylelint/rules/license-header.ts
6
6
  const { createPlugin, utils: { ruleMessages, validateOptions, report } } = stylelint;
7
7
  const ruleName = "license-header/header";
8
8
  const messages = ruleMessages(ruleName, {
@@ -73,8 +73,7 @@ var license_header_default = createPlugin(ruleName, Object.assign(ruleFunc, {
73
73
  ruleName,
74
74
  messages
75
75
  }));
76
- //#endregion
77
- //#region src/stylelint/package-utils.ts
76
+ // src/stylelint/package-utils.ts
78
77
  /**
79
78
  * Resolves the name of an extension or plugin package to the absolute path of
80
79
  * its entry file, as seen from this package.
@@ -97,8 +96,7 @@ var license_header_default = createPlugin(ruleName, Object.assign(ruleFunc, {
97
96
  function resolvePackage(name) {
98
97
  return fileURLToPath(import.meta.resolve(name));
99
98
  }
100
- //#endregion
101
- //#region src/stylelint/index.ts
99
+ // src/stylelint/index.ts
102
100
  /**
103
101
  * Generates a StyleLint configuration object targeting the source files in the
104
102
  * entire project.
@@ -201,7 +199,6 @@ function defineConfig(options) {
201
199
  overrides
202
200
  };
203
201
  }
204
- //#endregion
205
202
  export { defineConfig };
206
203
 
207
204
  //# sourceMappingURL=index.mjs.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.com/openxchange/appsuite/documents/commons/plugins/-/blob/main/packages/linter-presets/docs/stylelint/README.md',\n fixable: true,\n}\n\n/**\n * Cache for the contents of license header files, keyed by file path.\n */\nconst promiseCache = new Map<string, Promise<string>>()\n\n// functions ==================================================================\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","import { fileURLToPath } from 'node:url'\n\n// functions ==================================================================\n\n/**\n * Resolves the name of an extension or plugin package to the absolute path of\n * its entry file, as seen from this package.\n *\n * StyleLint resolves package names in the options `extends` and `plugins`\n * relative to the configuration file of the consumer project. With the strict\n * `node_modules` layout of pnpm, the packages installed as dependencies of\n * this package are not visible from there. An absolute path circumvents this\n * resolution. StyleLint resolves nested `extends` entries of the referenced\n * package relative to that package's own location, so the transitive packages\n * do not need any special handling.\n *\n * @param name\n * The name of the package to be resolved, optionally with a subpath (e.g.\n * 'stylelint-config-standard-vue/scss').\n *\n * @returns\n * The absolute path of the entry file of the package.\n */\nexport function resolvePackage(name: string): string {\n return fileURLToPath(import.meta.resolve(name))\n}\n","\nimport type { Config } from 'stylelint'\n\nimport licensePlugin from '@/stylelint/rules/license-header.ts'\nimport { resolvePackage } 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 quote character for string literals, or 'off' to disable the quote\n * check.\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 variant of `stylelint-config-standard-vue` 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 StyleLint configuration file in the project root. Should\n * 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 * linted stylesheet files. May be a path relative to the project root.\n */\n license?: string\n\n /**\n * Whether the project uses TailwindCSS. If set, the configuration package\n * `stylelint-config-tailwindcss` will be added.\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 * Project configuration options.\n *\n * @returns\n * The configuration object to be exported from the project's configuration\n * file (e.g. `stylelint.config.ts`).\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 (resolved to absolute paths,\n // see function 'resolvePackage' for details)\n const extensions = {\n base: [\n resolvePackage('stylelint-config-standard'),\n resolvePackage('@stylistic/stylelint-config'),\n ],\n scss: [\n resolvePackage('stylelint-config-standard-scss'),\n ],\n less: [\n resolvePackage('stylelint-config-standard-less'),\n ],\n vue: [\n resolvePackage((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(resolvePackage('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 {\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;;;;AAKA,MAAM,+BAAe,IAAI,IAA6B;;;;;;;;;;AAatD,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,KA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wBAAwB;EACxB,wBAAwB;EAGxB,SAAS,WAAW;EACpB,OAAO,MAAM;EACb;CACF;AACF"}
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/**\n * Cache for the contents of license header files, keyed by file path.\n */\nconst promiseCache = new Map<string, Promise<string>>()\n\n// functions ==================================================================\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","import { fileURLToPath } from 'node:url'\n\n// functions ==================================================================\n\n/**\n * Resolves the name of an extension or plugin package to the absolute path of\n * its entry file, as seen from this package.\n *\n * StyleLint resolves package names in the options `extends` and `plugins`\n * relative to the configuration file of the consumer project. With the strict\n * `node_modules` layout of pnpm, the packages installed as dependencies of\n * this package are not visible from there. An absolute path circumvents this\n * resolution. StyleLint resolves nested `extends` entries of the referenced\n * package relative to that package's own location, so the transitive packages\n * do not need any special handling.\n *\n * @param name\n * The name of the package to be resolved, optionally with a subpath (e.g.\n * 'stylelint-config-standard-vue/scss').\n *\n * @returns\n * The absolute path of the entry file of the package.\n */\nexport function resolvePackage(name: string): string {\n return fileURLToPath(import.meta.resolve(name))\n}\n","\nimport type { Config } from 'stylelint'\n\nimport licensePlugin from '@/stylelint/rules/license-header.ts'\nimport { resolvePackage } 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 quote character for string literals, or 'off' to disable the quote\n * check.\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 variant of `stylelint-config-standard-vue` 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 StyleLint configuration file in the project root. Should\n * 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 * linted stylesheet files. May be a path relative to the project root.\n */\n license?: string\n\n /**\n * Whether the project uses TailwindCSS. If set, the configuration package\n * `stylelint-config-tailwindcss` will be added.\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 * Project configuration options.\n *\n * @returns\n * The configuration object to be exported from the project's configuration\n * file (e.g. `stylelint.config.ts`).\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 (resolved to absolute paths,\n // see function 'resolvePackage' for details)\n const extensions = {\n base: [\n resolvePackage('stylelint-config-standard'),\n resolvePackage('@stylistic/stylelint-config'),\n ],\n scss: [\n resolvePackage('stylelint-config-standard-scss'),\n ],\n less: [\n resolvePackage('stylelint-config-standard-less'),\n ],\n vue: [\n resolvePackage((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(resolvePackage('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 {\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;;;;AAKA,MAAM,+BAAe,IAAI,IAA6B;;;;;;;;;;AAatD,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,M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ACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/linter-presets",
3
- "version": "1.31.0",
3
+ "version": "1.31.2",
4
4
  "description": "Configuration presets for ESLint and StyleLint",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,11 +26,11 @@
26
26
  "CHANGELOG.*"
27
27
  ],
28
28
  "dependencies": {
29
- "@babel/core": "^8.0.6",
30
- "@babel/eslint-parser": "^8.0.6",
29
+ "@babel/core": "^8.0.10",
30
+ "@babel/eslint-parser": "^8.0.7",
31
31
  "@eslint-community/eslint-plugin-eslint-comments": "^4.8.1",
32
- "@eslint-react/eslint-plugin": "^5.24.0",
33
- "@eslint-react/kit": "^5.24.0",
32
+ "@eslint-react/eslint-plugin": "^5.28.8",
33
+ "@eslint-react/kit": "^5.28.8",
34
34
  "@eslint/compat": "^2.1.1",
35
35
  "@eslint/config-helpers": "^0.7.0",
36
36
  "@eslint/core": "^1.2.1",
@@ -42,31 +42,30 @@
42
42
  "@stylistic/stylelint-plugin": "^5.3.1",
43
43
  "@types/json-schema": "^7.0.15",
44
44
  "@types/picomatch": "^4.0.3",
45
- "@vitest/eslint-plugin": "^1.6.27",
45
+ "@vitest/eslint-plugin": "^1.6.28",
46
46
  "@vue/eslint-config-typescript": "^14.9.0",
47
47
  "confusing-browser-globals": "^1.0.11",
48
- "empathic": "^2.1.0",
49
- "eslint-plugin-chai-expect": "^4.1.0",
48
+ "eslint-plugin-chai-expect": "^4.1.1",
50
49
  "eslint-plugin-codeceptjs": "^1.3.0",
51
50
  "eslint-plugin-depend": "^1.5.0",
52
51
  "eslint-plugin-eslint-plugin": "^7.6.2",
53
- "eslint-plugin-jest": "^29.16.6",
52
+ "eslint-plugin-jest": "^29.17.0",
54
53
  "eslint-plugin-jest-dom": "^5.10.1",
55
54
  "eslint-plugin-jest-extended": "^3.0.1",
56
- "eslint-plugin-jsdoc": "^65.1.0",
55
+ "eslint-plugin-jsdoc": "^65.4.2",
57
56
  "eslint-plugin-jsonc": "^3.4.2",
58
57
  "eslint-plugin-jsx-a11y": "^6.10.2",
59
58
  "eslint-plugin-license-header": "^0.9.0",
60
- "eslint-plugin-n": "^18.4.1",
59
+ "eslint-plugin-n": "^18.5.0",
61
60
  "eslint-plugin-no-unsanitized": "^4.1.5",
62
61
  "eslint-plugin-promise": "^7.3.0",
63
62
  "eslint-plugin-react-hooks": "^7.1.1",
64
63
  "eslint-plugin-react-refresh": "^0.5.7",
65
- "eslint-plugin-regexp": "^3.3.1",
64
+ "eslint-plugin-regexp": "^3.3.3",
66
65
  "eslint-plugin-testing-library": "^7.16.2",
67
- "eslint-plugin-vue": "^10.11.1",
68
- "eslint-plugin-yml": "^3.8.1",
69
- "globals": "^17.13.0",
66
+ "eslint-plugin-vue": "^10.12.0",
67
+ "eslint-plugin-yml": "^3.9.0",
68
+ "globals": "^17.14.0",
70
69
  "picomatch": "^4.0.7",
71
70
  "postcss-html": "^2.0.0",
72
71
  "stylelint-config-html": "^2.0.0",
@@ -79,20 +78,20 @@
79
78
  "stylelint-config-standard-scss": "^17.0.0",
80
79
  "stylelint-config-standard-vue": "^2.0.0",
81
80
  "stylelint-config-tailwindcss": "^1.0.1",
82
- "stylelint-less": "^4.2.1",
83
- "stylelint-scss": "^7.3.0",
84
- "typescript-eslint": "^8.71.0"
81
+ "stylelint-less": "^4.2.2",
82
+ "stylelint-scss": "^7.4.0",
83
+ "typescript-eslint": "^8.72.1"
85
84
  },
86
85
  "devDependencies": {
87
86
  "@jest/globals": "^30.5.2",
88
87
  "@open-xchange/tsconfig": "^0.2.4",
89
88
  "@types/confusing-browser-globals": "^1.0.3",
90
89
  "@types/react": "^19.3.0",
91
- "@typescript-eslint/utils": "^8.71.0",
92
- "eslint": "^10.12.0",
90
+ "@typescript-eslint/utils": "^8.72.1",
91
+ "eslint": "^10.14.0",
93
92
  "jest": "^30.5.2",
94
93
  "stylelint": "^17.16.0",
95
- "vitest": "^5.0.3"
94
+ "vitest": "^5.0.5"
96
95
  },
97
96
  "peerDependencies": {
98
97
  "eslint": "^9.35.0 || ^10.0.0",