@open-xchange/linter-presets 1.29.0 → 1.29.1

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## `1.29.1` – 2026-Aug-06
4
+
5
+ - fixed: (StyleLint) import all plugins and configs explicitly to avoid needing to hoist the packages in pnpm environments
6
+
3
7
  ## `1.29.0` – 2026-Aug-06
4
8
 
5
9
  - added: (ESLint) new option 'refHooks' for `env.react`
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/stylelint/index.ts"],"mappings":";;;;;KAaY,aAAa,eAAe;;;;UAOvB;;;;;;EAOf;;;;;;EAOA;;;;;UAQe;;;;;;EAOf;;;;EAKA,QAAQ;;;;;UAQO;;;;;EAMf;;;;;EAMA;;;;;EAMA;;;;EAKA,YAAY;;;;EAKZ,MAAM;;;;EAKN,QAAQ;;;;;;;;;;;;iBAeM,aAAa,SAAS,iBAAiB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/stylelint/index.ts"],"mappings":";;;;;KAYY,aAAa,eAAe;;;;UAOvB;;;;;;EAOf;;;;;;EAOA;;;;;UAQe;;;;;;EAOf;;;;EAKA,QAAQ;;;;;UAQO;;;;;EAMf;;;;;EAMA;;;;;EAMA;;;;EAKA,YAAY;;;;EAKZ,MAAM;;;;EAKN,QAAQ;;;;;;;;;;;;iBAeM,aAAa,SAAS,iBAAiB"}
@@ -1,8 +1,21 @@
1
1
  import { t as PathResolver } from "../resolver-Nkg5OKUN.mjs";
2
- import stylisticPlugin from "@stylistic/stylelint-plugin";
3
- import stylisticConfig from "@stylistic/stylelint-config";
4
2
  import { readFile } from "node:fs/promises";
5
3
  import stylelint from "stylelint";
4
+ import lessPlugin from "stylelint-less";
5
+ import scssPlugin from "stylelint-scss";
6
+ import htmlConfig from "stylelint-config-html";
7
+ import recommendedConfig from "stylelint-config-recommended";
8
+ import recommendedLessConfig from "stylelint-config-recommended-less";
9
+ import recommendedScssConfig from "stylelint-config-recommended-scss";
10
+ import recommendedVueConfig from "stylelint-config-recommended-vue";
11
+ import recommendedVueScssConfig from "stylelint-config-recommended-vue/scss";
12
+ import standardConfig from "stylelint-config-standard";
13
+ import standardLessConfig from "stylelint-config-standard-less";
14
+ import standardScssConfig from "stylelint-config-standard-scss";
15
+ import standardVueConfig from "stylelint-config-standard-vue";
16
+ import standardVueScssConfig from "stylelint-config-standard-vue/scss";
17
+ import stylisticPlugin from "@stylistic/stylelint-plugin";
18
+ import stylisticConfig from "@stylistic/stylelint-config";
6
19
  //#region src/stylelint/rules/license-header.ts
7
20
  const { createPlugin, utils: { ruleMessages, validateOptions, report } } = stylelint;
8
21
  const ruleName = "license-header/header";
@@ -72,6 +85,67 @@ var license_header_default = createPlugin(ruleName, Object.assign(ruleFunc, {
72
85
  messages
73
86
  }));
74
87
  //#endregion
88
+ //#region src/stylelint/package-utils.ts
89
+ const PLUGINS = {
90
+ "@stylistic/stylelint-plugin": stylisticPlugin,
91
+ "stylelint-less": lessPlugin,
92
+ "stylelint-scss": scssPlugin
93
+ };
94
+ const CONFIGS = {
95
+ "@stylistic/stylelint-config": stylisticConfig,
96
+ "stylelint-config-html": htmlConfig,
97
+ "stylelint-config-recommended": recommendedConfig,
98
+ "stylelint-config-recommended-less": recommendedLessConfig,
99
+ "stylelint-config-recommended-scss": recommendedScssConfig,
100
+ "stylelint-config-recommended-vue": recommendedVueConfig,
101
+ "stylelint-config-recommended-vue/scss": recommendedVueScssConfig,
102
+ "stylelint-config-standard": standardConfig,
103
+ "stylelint-config-standard-less": standardLessConfig,
104
+ "stylelint-config-standard-scss": standardScssConfig,
105
+ "stylelint-config-standard-vue": standardVueConfig,
106
+ "stylelint-config-standard-vue/scss": standardVueScssConfig
107
+ };
108
+ /**
109
+ * Resolves string entries in the configuration options `plugins` and `extends`
110
+ * to imported objects.
111
+ *
112
+ * @param config
113
+ * The configuration to be resolved.
114
+ */
115
+ function resolveEntries(config) {
116
+ config.plugins &&= [config.plugins].flat().map((entry) => {
117
+ if (typeof entry !== "string") return entry;
118
+ const resolved = PLUGINS[entry];
119
+ if (!resolved) throw new Error(`unknown plugin package '${entry}'`);
120
+ return resolved;
121
+ });
122
+ config.extends &&= [config.extends].flat().map((entry) => {
123
+ if (typeof entry !== "string") return entry;
124
+ const resolved = CONFIGS[entry];
125
+ if (!resolved) throw new Error(`unknown extension package '${entry}'`);
126
+ return resolveConfigPackages(resolved);
127
+ });
128
+ }
129
+ /**
130
+ * Recursively resolves string entries in the `extends` configuration option
131
+ * with the resolved packages. Needed to workaround broken import resolution in
132
+ * stylelint with pnpm.
133
+ *
134
+ * @template ConfigT
135
+ * The exact type of the configuration (e.g. override config with files).
136
+ *
137
+ * @param config
138
+ * The configuration to be resolved.
139
+ *
140
+ * @returns
141
+ * The passed configuration object with resolved extensions.
142
+ */
143
+ function resolveConfigPackages(config) {
144
+ resolveEntries(config);
145
+ config.overrides?.forEach(resolveEntries);
146
+ return config;
147
+ }
148
+ //#endregion
75
149
  //#region src/stylelint/index.ts
76
150
  /**
77
151
  * Generates a StyleLint configuration object targeting the source files in the
@@ -99,7 +173,6 @@ function defineConfig(options) {
99
173
  ...options.stylistic
100
174
  };
101
175
  const resolver = new PathResolver(options.root);
102
- const plugins = [];
103
176
  const overrides = [];
104
177
  const rules = {
105
178
  base: {
@@ -125,9 +198,7 @@ function defineConfig(options) {
125
198
  },
126
199
  less: {}
127
200
  };
128
- plugins.push(stylisticPlugin);
129
201
  Object.assign(rules.base, {
130
- ...stylisticConfig.rules,
131
202
  "@stylistic/declaration-colon-newline-after": null,
132
203
  "@stylistic/indentation": [stylistic.indent, { ignore: ["inside-parens"] }],
133
204
  "@stylistic/max-line-length": null,
@@ -137,16 +208,15 @@ function defineConfig(options) {
137
208
  });
138
209
  if (options.license) overrides.push({
139
210
  files: ["**/*.{css,scss,less}"],
140
- plugins: [license_header_default],
211
+ plugins: license_header_default,
141
212
  rules: { "license-header/header": resolver.path(options.license) }
142
213
  });
143
214
  if (options.rules) for (const [name, rule] of Object.entries(options.rules)) {
144
215
  const key = name.split("/")[0];
145
216
  (rules[key] ?? rules.base)[name] = rule;
146
217
  }
147
- return {
218
+ return resolveConfigPackages({
148
219
  ignoreFiles,
149
- plugins,
150
220
  extends: ["@stylistic/stylelint-config"],
151
221
  rules: rules.base,
152
222
  reportDescriptionlessDisables: null,
@@ -156,22 +226,22 @@ function defineConfig(options) {
156
226
  overrides: [
157
227
  {
158
228
  files: ["**/*.scss"],
159
- extends: ["stylelint-config-standard-scss"],
229
+ extends: "stylelint-config-standard-scss",
160
230
  rules: rules.scss
161
231
  },
162
232
  {
163
233
  files: ["**/*.less"],
164
- extends: ["stylelint-config-standard-less"],
234
+ extends: "stylelint-config-standard-less",
165
235
  rules: rules.less
166
236
  },
167
237
  {
168
238
  files: ["**/*.vue"],
169
- extends: [options.vue?.lang === "scss" ? "stylelint-config-standard-vue/scss" : "stylelint-config-standard-vue"],
239
+ extends: options.vue?.lang === "scss" ? "stylelint-config-standard-vue/scss" : "stylelint-config-standard-vue",
170
240
  rules: options.vue?.rules
171
241
  },
172
242
  ...overrides
173
243
  ]
174
- };
244
+ });
175
245
  }
176
246
  //#endregion
177
247
  export { defineConfig };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["licensePlugin"],"sources":["../../src/stylelint/rules/license-header.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, ConfigRuleSettings, Plugin } from 'stylelint'\nimport stylisticPlugin from '@stylistic/stylelint-plugin'\nimport stylisticConfig from '@stylistic/stylelint-config'\nimport licensePlugin from '@/stylelint/rules/license-header.ts'\n\nimport { PathResolver } from '@/utils/resolver.ts'\n\n// types ======================================================================\n\n/**\n * Configuration for multiple rules.\n */\nexport type RuleRecord = Record<string, ConfigRuleSettings<unknown, object>>\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 to be added to the global 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 * 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.\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 // all plugins to be loaded\n const plugins: Plugin[] = []\n\n // custom overrides\n const overrides: Config['overrides'] = []\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 },\n scss: {\n 'scss/dollar-variable-empty-line-before': null,\n 'scss/double-slash-comment-empty-line-before': null,\n },\n less: {},\n }\n\n // @stylistic plugin\n plugins.push(stylisticPlugin)\n Object.assign(rules.base, {\n ...stylisticConfig.rules,\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\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 // 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\n }\n }\n\n return {\n\n // ignore certain files and folders\n ignoreFiles,\n\n // language plugins\n plugins,\n\n // add recommended configurations\n extends: [\n '@stylistic/stylelint-config',\n ],\n\n // rules for all language types\n rules: rules.base,\n\n // check inline directives\n reportDescriptionlessDisables: null,\n reportInvalidScopeDisables: true,\n reportNeedlessDisables: true,\n reportUnscopedDisables: true,\n\n // overrides for custom languages\n overrides: [\n\n // '.scss' files\n {\n files: ['**/*.scss'],\n extends: ['stylelint-config-standard-scss'],\n rules: rules.scss,\n },\n\n // '.less' files\n {\n files: ['**/*.less'],\n extends: ['stylelint-config-standard-less'],\n rules: rules.less,\n },\n\n // '.vue' files\n {\n files: ['**/*.vue'],\n extends: [\n (options.vue?.lang === 'scss') ? 'stylelint-config-standard-vue/scss' : 'stylelint-config-standard-vue',\n ],\n rules: options.vue?.rules,\n },\n\n ...overrides,\n ],\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,MAAM,sBAAsB,OA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AgB;EACnB,8CAA8C;EAC9C,0BAA0B,CAAC,UAAU,QAAQ,EAAE,QAAQ,CAAC,eAAe,EAAE,CAAC;EAC1E,8BAA8B;EAC9B,kCAAkC;EAClC,gDAAgD;EAChD,4BAA6B,UAAU,WAAW,QAAS,OAAO,CAAC,UAAU,QAAQ,EAAE,aAAa,KAAK,CAAC;CAC5G,CAAC;CAGD,IAAI,QAAQ,SACV,UAAU,KAAK;EACb,OAAO,CAAC,sBAAsB;EAC9B,SAAS,CAACA,sBAAa;EACvB,OAAO,EACL,yBAAyB,SAAS,KAAK,QAAQ,OAAO,EACxD;CACF,CAAC;CAIH,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;CAGF,OAAO;EAGL;EAGA;EAGA,SAAS,CACP,6BACF;EAGA,OAAO,MAAM;EAGb,+BAA+B;EAC/B,4BAA4B;EAC5B,wBAAwB;EACxB,wBAAwB;EAGxB,WAAW;GAGT;IACE,OAAO,CAAC,WAAW;IACnB,SAAS,CAAC,gCAAgC;IAC1C,OAAO,MAAM;GACf;GAGA;IACE,OAAO,CAAC,WAAW;IACnB,SAAS,CAAC,gCAAgC;IAC1C,OAAO,MAAM;GACf;GAGA;IACE,OAAO,CAAC,UAAU;IAClB,SAAS,CACN,QAAQ,KAAK,SAAS,SAAU,uCAAuC,+BAC1E;IACA,OAAO,QAAQ,KAAK;GACtB;GAEA,GAAG;EACL;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.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'\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}\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, ConfigRuleSettings } 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 = Record<string, ConfigRuleSettings<unknown, object>>\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 to be added to the global 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 * 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.\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 overrides\n const overrides: Config['overrides'] = []\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 },\n scss: {\n 'scss/dollar-variable-empty-line-before': null,\n 'scss/double-slash-comment-empty-line-before': null,\n },\n less: {},\n }\n\n // override rules of @stylistic plugin\n Object.assign(rules.base, {\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\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 // 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\n }\n }\n\n return resolveConfigPackages({\n\n // ignore certain files and folders\n ignoreFiles,\n\n // add recommended configurations\n extends: [\n '@stylistic/stylelint-config',\n ],\n\n // rules for all language types\n rules: rules.base,\n\n // check inline directives\n reportDescriptionlessDisables: null,\n reportInvalidScopeDisables: true,\n reportNeedlessDisables: true,\n reportUnscopedDisables: true,\n\n // overrides for custom languages\n overrides: [\n\n // '.scss' files\n {\n files: ['**/*.scss'],\n extends: 'stylelint-config-standard-scss',\n rules: rules.scss,\n },\n\n // '.less' files\n {\n files: ['**/*.less'],\n extends: 'stylelint-config-standard-less',\n rules: rules.less,\n },\n\n // '.vue' files\n {\n files: ['**/*.vue'],\n extends: (options.vue?.lang === 'scss') ?\n 'stylelint-config-standard-vue/scss' :\n 'stylelint-config-standard-vue',\n rules: options.vue?.rules,\n },\n\n ...overrides,\n ],\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA,MAAM,EAAE,cAAc,OAAO,EAAE,cAAc,iBAAiB,aAAa;AAS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ANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/linter-presets",
3
- "version": "1.29.0",
3
+ "version": "1.29.1",
4
4
  "description": "Configuration presets for ESLint and StyleLint",
5
5
  "repository": {
6
6
  "type": "git",
@@ -69,10 +69,17 @@
69
69
  "globals": "^17.9.0",
70
70
  "picomatch": "^4.0.5",
71
71
  "postcss-html": "^2.0.0",
72
+ "stylelint-config-html": "^2.0.0",
73
+ "stylelint-config-recommended": "^18.0.0",
74
+ "stylelint-config-recommended-less": "^4.2.1",
75
+ "stylelint-config-recommended-scss": "^17.0.1",
76
+ "stylelint-config-recommended-vue": "^2.0.0",
72
77
  "stylelint-config-standard": "^40.0.0",
73
78
  "stylelint-config-standard-less": "^4.1.0",
74
79
  "stylelint-config-standard-scss": "^17.0.0",
75
80
  "stylelint-config-standard-vue": "^2.0.0",
81
+ "stylelint-less": "^4.2.1",
82
+ "stylelint-scss": "^7.2.0",
76
83
  "typescript-eslint": "^8.66.0"
77
84
  },
78
85
  "devDependencies": {