From 7d1b84702c1f13379657efebd4aa41dd8a989f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Sat, 3 Feb 2024 13:53:41 +0100 Subject: [PATCH] Start work on stylelint 16 --- .../crafty-preset-stylelint/build.config.js | 257 +----------------- packages/crafty-preset-stylelint/package.json | 7 +- .../packages/resolve-from.js | 1 - .../packages/stylelint-bin.js | 1 - .../packages/stylelint.js | 1 - .../src/commands/lint_css.js | 2 +- packages/crafty-preset-stylelint/src/dummy.js | 14 - .../build.config.js | 114 -------- .../stylelint-config-swissquote/common.js | 17 +- packages/stylelint-config-swissquote/index.js | 18 +- .../stylelint-config-swissquote/legacy.js | 9 +- .../stylelint-config-swissquote/package.json | 23 +- .../postcss-resolve-nested-selector.js | 1 - .../packages/postcss-selector-parser.js | 1 - .../packages/postcss-value-parser.js | 1 - ...ylelint-no-unsupported-browser-features.js | 1 - .../packages/stylelint-prettier.js | 1 - .../packages/stylelint-scss.js | 1 - .../recommended.js | 11 +- .../shims/lodash.js | 45 --- .../shims/prettier-parser.js | 10 - .../shims/stylelint-keywordSets.js | 8 - .../shims/stylelint.js | 9 - .../src/__tests__/common.js | 6 +- .../src/__tests__/recommended.js | 6 +- .../rules/__tests__/no-block-inside-block.js | 5 +- .../rules/__tests__/no-hack-reassignment.js | 5 +- .../src/rules/__tests__/no-negative-var.js | 5 +- .../__tests__/no-state-without-component.js | 5 +- .../rules/__tests__/no-type-outside-scope.js | 5 +- .../__tests__/no-utility-reassignment.js | 5 +- .../no-variable-in-transpiled-function.js | 5 +- .../src/rules/no-block-inside-block.js | 15 +- .../src/rules/no-hack-reassignment.js | 16 +- .../src/rules/no-negative-var.js | 15 +- .../src/rules/no-state-without-component.js | 15 +- .../src/rules/no-type-outside-scope.js | 21 +- .../src/rules/no-utility-reassignment.js | 15 +- .../no-variable-in-transpiled-function.js | 20 +- .../src/testUtils/ruleTester.js | 10 +- .../utils/__tests__/resolveNestedSelector.js | 15 +- .../cssRuleHasSelectorEndingWithColon.js | 2 +- .../src/utils/parseSelector.js | 6 +- .../src/utils/resolveNestedSelector.js | 3 +- 44 files changed, 166 insertions(+), 587 deletions(-) delete mode 100644 packages/crafty-preset-stylelint/packages/resolve-from.js delete mode 100644 packages/crafty-preset-stylelint/packages/stylelint-bin.js delete mode 100644 packages/crafty-preset-stylelint/packages/stylelint.js delete mode 100644 packages/crafty-preset-stylelint/src/dummy.js delete mode 100644 packages/stylelint-config-swissquote/build.config.js delete mode 100644 packages/stylelint-config-swissquote/packages/postcss-resolve-nested-selector.js delete mode 100644 packages/stylelint-config-swissquote/packages/postcss-selector-parser.js delete mode 100644 packages/stylelint-config-swissquote/packages/postcss-value-parser.js delete mode 100644 packages/stylelint-config-swissquote/packages/stylelint-no-unsupported-browser-features.js delete mode 100644 packages/stylelint-config-swissquote/packages/stylelint-prettier.js delete mode 100644 packages/stylelint-config-swissquote/packages/stylelint-scss.js delete mode 100644 packages/stylelint-config-swissquote/shims/lodash.js delete mode 100644 packages/stylelint-config-swissquote/shims/prettier-parser.js delete mode 100644 packages/stylelint-config-swissquote/shims/stylelint-keywordSets.js delete mode 100644 packages/stylelint-config-swissquote/shims/stylelint.js diff --git a/packages/crafty-preset-stylelint/build.config.js b/packages/crafty-preset-stylelint/build.config.js index 3a762c301..dd85bf5a8 100644 --- a/packages/crafty-preset-stylelint/build.config.js +++ b/packages/crafty-preset-stylelint/build.config.js @@ -1,258 +1,15 @@ -const fs = require("fs"); -const path = require("path"); - -const { getExternals } = require("../../utils/externals"); - -const singlePackages = [ - "balanced-match", - "color-convert", - "gulp-postcss", - "gulp-rename", - "is-fullwidth-code-point", - "is-plain-object", - "postcss-media-query-parser", - "resolve-from", - "slice-ansi", - "string-width", - "style-search", - "supports-color", - "supports-hyperlinks", - "table", - "css-tree", - "@csstools/selector-specificity", - "mathml-tag-names", - "colord", - "known-css-properties", - "svg-tags", - "has-flag" -]; +import { getExternals } from "../../utils/externals.js"; const externals = { // Provided by other Crafty packages ...getExternals(), - - ...Object.fromEntries( - singlePackages.map((pkg) => [pkg, `../${pkg}/index.js`]) - ), - - "@ronilaukkarinen/gulp-stylelint": "../ronilaukkarinen-gulp-stylelint/index.js", - - "schema-utils": "schema-utils", - postcss: "postcss", - "postcss/package.json": "postcss/package.json", - "/postcss/lib(/.*)/": "postcss/lib$1", - "@babel/code-frame": "@babel/code-frame", - - // Provide a simplified package data normalizer - "normalize-package-data": "../../packages/normalize-package-data.js", - - // Not used as we pass the configuration directly, can be excluded from the bundle - "postcss-load-config": "../../src/dummy.js", - cosmiconfig: "../../src/dummy.js", + stylelint: "stylelint" }; -const ruleExternals = { - ...externals, - "@csstools/media-query-list-parser": "../csstools/media-query-list-parser.js", - "@csstools/css-tokenizer": "../csstools/css-tokenizer.js", - "@csstools/css-parser-algorithms": "../csstools/css-parser-algorithms.js", -} - -const stylelintSource = []; - -stylelintSource.push({ - pkg: "stylelint", - name: "stylelint", - entryFile: `dist/stylelint/index.js`, -}); - -stylelintSource.push({ - pkg: "stylelint/bin/stylelint", - name: "stylelintBin", - entryFile: `dist/stylelint/bin.js`, -}); - -stylelintSource.push({ - pkg: "stylelint/lib/reference/atKeywords.js", - name: "libReferenceAtKeywords", - entryFile: `dist/stylelint/reference-atKeywords.js`, -}); -ruleExternals["../../reference/atKeywords"] = "./reference-atKeywords.js"; - -stylelintSource.push({ - pkg: "stylelint/lib/reference/functions.js", - name: "libReferenceFunctions", - entryFile: `dist/stylelint/reference-functions.js`, -}); -ruleExternals["../../reference/functions"] = "./reference-functions.js"; - -stylelintSource.push({ - pkg: "stylelint/lib/reference/keywords.js", - name: "libReferenceKeywords", - entryFile: `dist/stylelint/reference-keywords.js`, -}); -ruleExternals["../../reference/keywords"] = "./reference-keywords.js"; - -stylelintSource.push({ - pkg: "stylelint/lib/reference/mediaFeatures.js", - name: "libReferenceMediaFeatures", - entryFile: `dist/stylelint/reference-mediaFeatures.js`, -}); -ruleExternals["../../reference/mediaFeatures"] = "./reference-mediaFeatures.js"; - -stylelintSource.push({ - pkg: "stylelint/lib/reference/properties.js", - name: "libReferenceProperties", - entryFile: `dist/stylelint/reference-properties.js`, -}); -ruleExternals["../../reference/properties"] = "./reference-properties.js"; - -stylelintSource.push({ - pkg: "stylelint/lib/reference/selectors.js", - name: "libReferenceSelectors", - entryFile: `dist/stylelint/reference-selectors.js`, -}); -ruleExternals["../../reference/selectors"] = "./reference-selectors.js"; - -stylelintSource.push({ - pkg: "stylelint/lib/reference/units.js", - name: "libReferenceUnits", - entryFile: `dist/stylelint/reference-units.js`, -}); -ruleExternals["../../reference/units"] = "./reference-units.js"; - -// Extract all formatters -// ---------------------- -const formatters = fs - .readdirSync( - path.dirname(require.resolve("stylelint/lib/formatters/index.js")) - ) - .filter((file) => file != "index.js") - .map((file) => { - ruleExternals[`./${file.replace(".js", "")}`] = `./${file}`; - - return (builder) => builder(`stylelint-formatters-${file.replace(".js", "")}`) - .source( - path.relative( - process.cwd(), - require.resolve(`stylelint/lib/formatters/${file}`) - ) - ) - .destination(`dist/stylelint/${file}`) - .options({ - sourceMap: false, - externals: ruleExternals, - }); - } - ); - -// Extract linting rules and utilities -// ----------------------------------- - -const stylelintRules = fs - .readdirSync(path.dirname(require.resolve("stylelint/lib/rules/index.js"))) - .filter((file) => file != "index.js"); - -const rules = stylelintRules - .map((file) => { - // Utilities that are used by many rules - if (file.includes(".js")) { - ruleExternals[`../${file.replace(".js", "")}`] = `./rule-util-${file}`; - //ruleExternals[`./${file.replace(".js", "")}`] = `./rule-util-${file}`; - //ruleExternals[`stylelint/lib/rules/${file}`] = `./${file}`; - - const functionName = file.replace(".js", "").replace(/-/g, "_"); - stylelintSource.push({ - pkg: `stylelint/lib/rules/${file}`, - name: functionName, - entryFile: `dist/stylelint/rule-util-${file}`, - }); - - return false; - } - - // Actual rules are inside folders - ruleExternals[`./${file}`] = `./${file}`; - return (builder) => - builder(`stylelint-rules-${file}`) - .source( - path.relative( - process.cwd(), - require.resolve(`stylelint/lib/rules/${file}`) - ) - ) - .destination( - file.includes(".js") - ? `dist/stylelint/${file}` - : `dist/stylelint/${file}.js` - ) - .options({ - sourceMap: false, - externals: ruleExternals, - }); - }) - .filter(Boolean); - -const stylelintUtils = fs - .readdirSync( - path.dirname(require.resolve("stylelint/lib/utils/arrayEqual.js")) - ) - .filter((file) => file.includes(".js")); - -stylelintUtils.forEach((file) => { - // Create externals to refer to the util - ruleExternals[`../../../utils/${file.replace(".js", "")}`] = `./util-${file}`; - ruleExternals[`../../utils/${file.replace(".js", "")}`] = `./util-${file}`; - ruleExternals[`../utils/${file.replace(".js", "")}`] = `./util-${file}`; - - const functionName = file.replace(".js", "").replace(/-/g, "_"); - - stylelintSource.push({ - pkg: `stylelint/lib/utils/${file}`, - name: functionName, - entryFile: `dist/stylelint/util-${file}`, - }); -}); - -module.exports = [ - (builder) => - builder("csstools") - .packages((pkgBuilder) => { - pkgBuilder - .package("@csstools/media-query-list-parser", "mediaQueryListParser", "dist/csstools/media-query-list-parser.js") - .package("@csstools/css-tokenizer", "cssTokenizer", "dist/csstools/css-tokenizer.js") - .package("@csstools/css-parser-algorithms", "cssParserAlgorithms", "dist/csstools/css-parser-algorithms.js") - - }) - .destination(`dist/csstools/index.js`) - .externals(externals), - (builder) => - builder("stylelint") - .packages((pkgBuilder) => { - stylelintSource.forEach((entry) => { - pkgBuilder.package(entry.pkg, entry.name, entry.entryFile); - }); - }) - .destination(`dist/stylelint/stylelint.js`) - .externals(ruleExternals), - - (builder) => { - const newExternals = { ...externals }; - delete newExternals["@ronilaukkarinen/gulp-stylelint"]; - - return builder("@ronilaukkarinen/gulp-stylelint") +export default [ + (builder) => builder("@ronilaukkarinen/gulp-stylelint") + .rspack() + .esm() .package() - .externals({ ...newExternals, stylelint: "../stylelint/index.js" }); - }, - ...singlePackages.map((pkg) => { - const newExternals = { ...externals }; - delete newExternals[pkg]; - - return (builder) => - builder(pkg) - .package() - .externals(newExternals); - }), - ...formatters, - ...rules + .externals(externals) ]; diff --git a/packages/crafty-preset-stylelint/package.json b/packages/crafty-preset-stylelint/package.json index 6a28b9e23..bbbf447bb 100644 --- a/packages/crafty-preset-stylelint/package.json +++ b/packages/crafty-preset-stylelint/package.json @@ -8,6 +8,7 @@ "access": "public" }, "main": "src/index.js", + "type": "module", "scripts": { "lint": "node ../crafty-preset-eslint/src/commands/jsLint.js --preset recommended --preset node src", "build": "node ../../utils/build.mjs" @@ -20,13 +21,13 @@ "@swissquote/crafty-preset-prettier": "1.24.0", "@swissquote/stylelint-config-swissquote": "1.24.0", "postcss": "8.4.33", - "postcss-scss": "4.0.9" + "postcss-scss": "4.0.9", + "stylelint": "16.2.1" }, "devDependencies": { "@ronilaukkarinen/gulp-stylelint": "14.1.2", "is-plain-object": "5.0.0", - "resolve-from": "5.0.0", - "stylelint": "15.10.0" + "resolve-from": "5.0.0" }, "engines": { "node": ">=18" diff --git a/packages/crafty-preset-stylelint/packages/resolve-from.js b/packages/crafty-preset-stylelint/packages/resolve-from.js deleted file mode 100644 index b4b4000c1..000000000 --- a/packages/crafty-preset-stylelint/packages/resolve-from.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/resolve-from/index.js"); diff --git a/packages/crafty-preset-stylelint/packages/stylelint-bin.js b/packages/crafty-preset-stylelint/packages/stylelint-bin.js deleted file mode 100644 index a8229f088..000000000 --- a/packages/crafty-preset-stylelint/packages/stylelint-bin.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/stylelint/bin.js"); diff --git a/packages/crafty-preset-stylelint/packages/stylelint.js b/packages/crafty-preset-stylelint/packages/stylelint.js deleted file mode 100644 index 57d548bfb..000000000 --- a/packages/crafty-preset-stylelint/packages/stylelint.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/stylelint/index.js"); diff --git a/packages/crafty-preset-stylelint/src/commands/lint_css.js b/packages/crafty-preset-stylelint/src/commands/lint_css.js index cbb16a779..fa487bd12 100755 --- a/packages/crafty-preset-stylelint/src/commands/lint_css.js +++ b/packages/crafty-preset-stylelint/src/commands/lint_css.js @@ -59,4 +59,4 @@ if (process.argv.indexOf("--custom-syntax") === -1) { process.argv.push(require.resolve("postcss-scss")); } -require("../../packages/stylelint-bin"); +require("stylelint/bin/stylelint.mjs"); diff --git a/packages/crafty-preset-stylelint/src/dummy.js b/packages/crafty-preset-stylelint/src/dummy.js deleted file mode 100644 index c0e37bbcd..000000000 --- a/packages/crafty-preset-stylelint/src/dummy.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - cosmiconfig(name, options) { - return { - load(searchPath) { - const config = require(searchPath); - - return options.transform({ config }); - }, - search() { - return null; - } - }; - } -}; diff --git a/packages/stylelint-config-swissquote/build.config.js b/packages/stylelint-config-swissquote/build.config.js deleted file mode 100644 index a2f0f2712..000000000 --- a/packages/stylelint-config-swissquote/build.config.js +++ /dev/null @@ -1,114 +0,0 @@ -const { getExternals } = require("../../utils/externals"); - -const commonExternals = { - // Provided by other Crafty packages - ...getExternals(), - - stylelint: "../../shims/stylelint.js", - "stylelint/lib/utils/optionsMatches": - "../stylelint-utils/stylelint-optionsMatches.js" -}; - -const FAKE_PRETTIER_PARSER = "../../shims/prettier-parser.js"; - -module.exports = [ - builder => - builder("stylelint-prettier") - .package() - .externals({ - ...commonExternals, - - // We don't need most prettier parsers - "./parser-angular.js": FAKE_PRETTIER_PARSER, - "./parser-babel.js": FAKE_PRETTIER_PARSER, - "./parser-espree.js": FAKE_PRETTIER_PARSER, - "./parser-flow.js": FAKE_PRETTIER_PARSER, - "./parser-glimmer.js": FAKE_PRETTIER_PARSER, - "./parser-graphql.js": FAKE_PRETTIER_PARSER, - "./parser-html.js": FAKE_PRETTIER_PARSER, - "./parser-markdown.js": FAKE_PRETTIER_PARSER, - "./parser-meriyah.js": FAKE_PRETTIER_PARSER, - "./parser-typescript.js": FAKE_PRETTIER_PARSER, - "./parser-yaml.js": FAKE_PRETTIER_PARSER - }), - builder => builder("postcss-selector-parser").package(), - builder => builder("postcss-resolve-nested-selector").package(), - - builder => builder("postcss-value-parser").package(), - builder => - builder("stylelint-scss") - .package() - .externals({ - ...commonExternals, - - // We use other packages created here - "postcss-selector-parser": "../postcss-selector-parser/index.js", - "postcss-value-parser": "../postcss-value-parser/index.js", - "postcss-resolve-nested-selector": - "../postcss-resolve-nested-selector/index.js", - - // We mock the few lodash functions really used - lodash: "../../shims/lodash.js" - }), - builder => - builder("stylelint-no-unsupported-browser-features") - .externals({ - ...commonExternals, - - postcss: "postcss", - "postcss/lib/result": "postcss/lib/result", - "postcss/lib/list": "postcss/lib/list", - - // We keep postcss-scss external so we can have it in common with preset-postcss - "postcss-scss": "postcss-scss", - - // Used by stylelint-no-unsupported-browser-features - "caniuse-lite": "caniuse-lite", - "/caniuse-lite(/.*)/": "caniuse-lite$1", - - // We mock the few lodash functions really used - lodash: "../../shims/lodash.js" - }) - .package(), - builder => - builder("stylelint-utils") - .packages(pkg => - pkg - .package( - "stylelint/lib/utils/declarationValueIndex", - "declarationValueIndex", - "dist/stylelint-utils/stylelint-declarationValueIndex.js" - ) - .package( - "stylelint/lib/utils/isStandardSyntaxFunction", - "isStandardSyntaxFunction", - "dist/stylelint-utils/stylelint-isStandardSyntaxFunction.js" - ) - .package( - "stylelint/lib/utils/isStandardSyntaxRule", - "isStandardSyntaxRule", - "dist/stylelint-utils/stylelint-isStandardSyntaxRule.js" - ) - .package( - "stylelint/lib/utils/isStandardSyntaxSelector", - "isStandardSyntaxSelector", - "dist/stylelint-utils/stylelint-isStandardSyntaxSelector.js" - ) - .package( - "stylelint/lib/utils/isKeyframeSelector", - "isKeyframeSelector", - "dist/stylelint-utils/stylelint-isKeyframeSelector.js" - ) - .package( - "stylelint/lib/utils/optionsMatches", - "optionMatches", - "dist/stylelint-utils/stylelint-optionsMatches.js" - ) - ) - .externals({ - "../reference/keywordSets": "../../shims/stylelint-keywordSets.js" - }) - .options({ - sourceMap: false - }) -]; diff --git a/packages/stylelint-config-swissquote/common.js b/packages/stylelint-config-swissquote/common.js index 548afaa16..b1f2daa25 100644 --- a/packages/stylelint-config-swissquote/common.js +++ b/packages/stylelint-config-swissquote/common.js @@ -1,3 +1,10 @@ +import { createRequire } from "node:module" +import { fileURLToPath} from 'url'; +import path from 'path'; + +const require = createRequire(import.meta.url) +const __dirname = fileURLToPath(new URL('.', import.meta.url)); + // Taken from https://github.com/stylelint/stylelint-config-suitcss/ // Changes since last import: https://github.com/suitcss/stylelint-config-suitcss/compare/4e09f16f7340d610348059ab73f24fb11488152d...master @@ -13,12 +20,12 @@ function warn(value, options) { return [value || true, opt]; } -module.exports = { +export default { plugins: [ - require.resolve("./index"), - require.resolve("./packages/stylelint-prettier"), - require.resolve("./packages/stylelint-scss"), - require.resolve("./packages/stylelint-no-unsupported-browser-features") + path.join(__dirname, "index.js"), + require.resolve("stylelint-prettier"), + require.resolve("stylelint-scss"), + require.resolve("stylelint-no-unsupported-browser-features") ], rules: { // Formatting diff --git a/packages/stylelint-config-swissquote/index.js b/packages/stylelint-config-swissquote/index.js index b168e92d4..711265215 100644 --- a/packages/stylelint-config-swissquote/index.js +++ b/packages/stylelint-config-swissquote/index.js @@ -1,14 +1,14 @@ -const stylelint = require("./shims/stylelint"); +import stylelint from "stylelint"; -const noBlockInsideBlock = require("./src/rules/no-block-inside-block"); -const noUtilityReassignment = require("./src/rules/no-utility-reassignment"); -const noHackReassignment = require("./src/rules/no-hack-reassignment"); -const noStateWithoutComponent = require("./src/rules/no-state-without-component"); -const noTypeOutsideScope = require("./src/rules/no-type-outside-scope"); -const noNegativeVar = require("./src/rules/no-negative-var"); -const noVariableInTranspiledFunction = require("./src/rules/no-variable-in-transpiled-function"); +import noBlockInsideBlock from "./src/rules/no-block-inside-block.js"; +import noUtilityReassignment from "./src/rules/no-utility-reassignment.js"; +import noHackReassignment from "./src/rules/no-hack-reassignment.js"; +import noStateWithoutComponent from "./src/rules/no-state-without-component.js"; +import noTypeOutsideScope from "./src/rules/no-type-outside-scope.js"; +import noNegativeVar from "./src/rules/no-negative-var.js"; +import noVariableInTranspiledFunction from "./src/rules/no-variable-in-transpiled-function.js"; -module.exports = [ +export default [ stylelint.createPlugin(noBlockInsideBlock.ruleName, noBlockInsideBlock), stylelint.createPlugin(noUtilityReassignment.ruleName, noUtilityReassignment), stylelint.createPlugin(noHackReassignment.ruleName, noHackReassignment), diff --git a/packages/stylelint-config-swissquote/legacy.js b/packages/stylelint-config-swissquote/legacy.js index d0d2ceedf..74c18dc67 100644 --- a/packages/stylelint-config-swissquote/legacy.js +++ b/packages/stylelint-config-swissquote/legacy.js @@ -1,4 +1,9 @@ -module.exports = { - extends: [require.resolve("./common")], +import { fileURLToPath} from 'url'; +import path from 'path'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); + +export default { + extends: [path.join(__dirname, "common.js")], rules: {} }; diff --git a/packages/stylelint-config-swissquote/package.json b/packages/stylelint-config-swissquote/package.json index 6bc3926e7..195c01002 100644 --- a/packages/stylelint-config-swissquote/package.json +++ b/packages/stylelint-config-swissquote/package.json @@ -8,32 +8,31 @@ "access": "public" }, "main": "index.js", + "type": "module", "dependencies": { "@swissquote/crafty": "1.24.0", "caniuse-lite": "^1.0.30001582", - "postcss-scss": "4.0.9" + "postcss-resolve-nested-selector": "0.1.1", + "postcss-scss": "4.0.9", + "postcss-selector-parser": "6.0.15", + "postcss-value-parser": "4.2.0", + "stylelint": "16.2.1", + "stylelint-no-unsupported-browser-features": "8.0.1", + "stylelint-prettier": "5.0.0", + "stylelint-scss": "6.1.0" }, "devDependencies": { "ava": "6.1.1", "c8": "9.1.0", "postcss": "8.4.33", - "postcss-resolve-nested-selector": "0.1.1", - "postcss-selector-parser": "6.0.15", - "postcss-value-parser": "4.2.0", - "prettier": "2.8.8", - "stylelint": "15.10.0", - "stylelint-no-unsupported-browser-features": "7.0.0", - "stylelint-prettier": "3.0.0", - "stylelint-scss": "5.3.2" + "prettier": "3.2.4" }, "peerDependencies": { "@swissquote/crafty-commons": "1.24.0", - "postcss": "^8.0.0", - "stylelint": "^15.0.0" + "postcss": "^8.0.0" }, "scripts": { "lint": "node ../crafty-preset-eslint/src/commands/jsLint.js --preset recommended --preset node '*.js' src", - "build": "node ../../utils/build.mjs", "test": "ava", "test:ci": "c8 --clean --reporter=text --reporter=lcov --reporter=html --include=src --include=packages --include='*.js' ava" }, diff --git a/packages/stylelint-config-swissquote/packages/postcss-resolve-nested-selector.js b/packages/stylelint-config-swissquote/packages/postcss-resolve-nested-selector.js deleted file mode 100644 index b18493534..000000000 --- a/packages/stylelint-config-swissquote/packages/postcss-resolve-nested-selector.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/postcss-resolve-nested-selector/index.js"); diff --git a/packages/stylelint-config-swissquote/packages/postcss-selector-parser.js b/packages/stylelint-config-swissquote/packages/postcss-selector-parser.js deleted file mode 100644 index 96748d844..000000000 --- a/packages/stylelint-config-swissquote/packages/postcss-selector-parser.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/postcss-selector-parser/index.js"); diff --git a/packages/stylelint-config-swissquote/packages/postcss-value-parser.js b/packages/stylelint-config-swissquote/packages/postcss-value-parser.js deleted file mode 100644 index 933906ff6..000000000 --- a/packages/stylelint-config-swissquote/packages/postcss-value-parser.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/postcss-value-parser/index.js"); diff --git a/packages/stylelint-config-swissquote/packages/stylelint-no-unsupported-browser-features.js b/packages/stylelint-config-swissquote/packages/stylelint-no-unsupported-browser-features.js deleted file mode 100644 index 0a7e82b0b..000000000 --- a/packages/stylelint-config-swissquote/packages/stylelint-no-unsupported-browser-features.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/stylelint-no-unsupported-browser-features/index.js"); diff --git a/packages/stylelint-config-swissquote/packages/stylelint-prettier.js b/packages/stylelint-config-swissquote/packages/stylelint-prettier.js deleted file mode 100644 index a2af97c68..000000000 --- a/packages/stylelint-config-swissquote/packages/stylelint-prettier.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/stylelint-prettier/index.js"); diff --git a/packages/stylelint-config-swissquote/packages/stylelint-scss.js b/packages/stylelint-config-swissquote/packages/stylelint-scss.js deleted file mode 100644 index df9cf05ca..000000000 --- a/packages/stylelint-config-swissquote/packages/stylelint-scss.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dist/stylelint-scss/index.js") diff --git a/packages/stylelint-config-swissquote/recommended.js b/packages/stylelint-config-swissquote/recommended.js index b137d3a89..a79a0c1ee 100644 --- a/packages/stylelint-config-swissquote/recommended.js +++ b/packages/stylelint-config-swissquote/recommended.js @@ -1,6 +1,11 @@ -module.exports = { - extends: [require.resolve("./common")], - plugins: [require.resolve("./index")], +import { fileURLToPath} from 'url'; +import path from 'path'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); + +export default { + extends: [path.join(__dirname, "common.js")], + plugins: [path.join(__dirname, "index.js")], rules: { // Swissquote Guidelines // --------------------------------------------------------------------- diff --git a/packages/stylelint-config-swissquote/shims/lodash.js b/packages/stylelint-config-swissquote/shims/lodash.js deleted file mode 100644 index 50e882cdd..000000000 --- a/packages/stylelint-config-swissquote/shims/lodash.js +++ /dev/null @@ -1,45 +0,0 @@ -// Since the used modules only use a tiny fraction of lodash we don't want that huge module -// Reimplement them here waiting for https://github.com/stylelint-scss/stylelint-scss/pull/554 to be finished - -function isBoolean(value) { - return typeof value === "boolean" || value instanceof Boolean; -} - -function isNumber(value) { - return typeof value === "number" || value instanceof Number; -} - -function isRegExp(value) { - return value instanceof RegExp; -} - -function isString(value) { - return typeof value === "string" || value instanceof String; -} - -/** - * All credits go to https://github.com/developit/dlv - */ -/* eslint-disable no-param-reassign */ -function get(obj, key, def, p, undef) { - key = key.split ? key.split(".") : key; - for (p = 0; p < key.length; p++) { - obj = obj ? obj[key[p]] : undef; - } - return obj === undef ? def : obj; -} - -function pick(obj, keys) { - return Object.fromEntries( - Object.entries(obj).filter(entry => keys.indexOf(entry[0]) > -1) - ); -} - -module.exports = { - isBoolean, - isNumber, - isRegExp, - isString, - get, - pick -}; diff --git a/packages/stylelint-config-swissquote/shims/prettier-parser.js b/packages/stylelint-config-swissquote/shims/prettier-parser.js deleted file mode 100644 index 7066b6e07..000000000 --- a/packages/stylelint-config-swissquote/shims/prettier-parser.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - parsers: new Proxy( - {}, - { - get: function (target, prop, receiver) { - return {}; - }, - } - ) -}; diff --git a/packages/stylelint-config-swissquote/shims/stylelint-keywordSets.js b/packages/stylelint-config-swissquote/shims/stylelint-keywordSets.js deleted file mode 100644 index 65d0afbfc..000000000 --- a/packages/stylelint-config-swissquote/shims/stylelint-keywordSets.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -const keywordSets = {}; - -// Include only these keywords -keywordSets.keyframeSelectorKeywords = new Set(['from', 'to']); - -module.exports = keywordSets; \ No newline at end of file diff --git a/packages/stylelint-config-swissquote/shims/stylelint.js b/packages/stylelint-config-swissquote/shims/stylelint.js deleted file mode 100644 index 4fc527020..000000000 --- a/packages/stylelint-config-swissquote/shims/stylelint.js +++ /dev/null @@ -1,9 +0,0 @@ -// Stylelint is bundled with Crafty -// If this package is used within Crafty, we need to use it from "@swissquote/crafty-preset-stylelint" -// Otherwise we fallback in loading stylelint directly - -try { - module.exports = require("@swissquote/crafty-preset-stylelint/packages/stylelint.js"); -} catch (e) { - module.exports = require("stylelint"); -} diff --git a/packages/stylelint-config-swissquote/src/__tests__/common.js b/packages/stylelint-config-swissquote/src/__tests__/common.js index b1e4dc1cb..4b9d9c25e 100644 --- a/packages/stylelint-config-swissquote/src/__tests__/common.js +++ b/packages/stylelint-config-swissquote/src/__tests__/common.js @@ -1,8 +1,8 @@ -const test = require("ava"); +import test from "ava"; -const stylelint = require("stylelint"); +import stylelint from "stylelint"; -const config = require("../../common"); +import config from "../../common.js"; const validCss = ` .Form { diff --git a/packages/stylelint-config-swissquote/src/__tests__/recommended.js b/packages/stylelint-config-swissquote/src/__tests__/recommended.js index a7442e328..432854c4b 100644 --- a/packages/stylelint-config-swissquote/src/__tests__/recommended.js +++ b/packages/stylelint-config-swissquote/src/__tests__/recommended.js @@ -1,8 +1,8 @@ -const test = require("ava"); +import test from "ava"; -const stylelint = require("stylelint"); +import stylelint from "stylelint"; -const config = require("../../recommended"); +import config from "../../recommended.js"; const validCss = `/** @define Form */ diff --git a/packages/stylelint-config-swissquote/src/rules/__tests__/no-block-inside-block.js b/packages/stylelint-config-swissquote/src/rules/__tests__/no-block-inside-block.js index 7e44495fa..4f0bdcbed 100644 --- a/packages/stylelint-config-swissquote/src/rules/__tests__/no-block-inside-block.js +++ b/packages/stylelint-config-swissquote/src/rules/__tests__/no-block-inside-block.js @@ -1,5 +1,6 @@ -const testRule = require("../../testUtils/ruleTester"); -const { ruleName } = require("../no-block-inside-block"); +import testRule from "../../testUtils/ruleTester.js"; +import rule from "../no-block-inside-block.js"; +const { ruleName } = rule; testRule({ plugins: ["./index.js"], diff --git a/packages/stylelint-config-swissquote/src/rules/__tests__/no-hack-reassignment.js b/packages/stylelint-config-swissquote/src/rules/__tests__/no-hack-reassignment.js index 3dbf18b94..c4f058a86 100644 --- a/packages/stylelint-config-swissquote/src/rules/__tests__/no-hack-reassignment.js +++ b/packages/stylelint-config-swissquote/src/rules/__tests__/no-hack-reassignment.js @@ -1,5 +1,6 @@ -const testRule = require("../../testUtils/ruleTester"); -const { ruleName, messages } = require("../no-hack-reassignment"); +import testRule from "../../testUtils/ruleTester.js"; +import rule from "../no-hack-reassignment.js"; +const { ruleName, messages } = rule; testRule({ plugins: ["./index.js"], diff --git a/packages/stylelint-config-swissquote/src/rules/__tests__/no-negative-var.js b/packages/stylelint-config-swissquote/src/rules/__tests__/no-negative-var.js index cf5804ca5..6268fac8a 100644 --- a/packages/stylelint-config-swissquote/src/rules/__tests__/no-negative-var.js +++ b/packages/stylelint-config-swissquote/src/rules/__tests__/no-negative-var.js @@ -1,5 +1,6 @@ -const testRule = require("../../testUtils/ruleTester"); -const { ruleName } = require("../no-negative-var"); +import testRule from "../../testUtils/ruleTester.js"; +import rule from "../no-negative-var.js"; +const { ruleName } = rule; testRule({ plugins: ["./index.js"], diff --git a/packages/stylelint-config-swissquote/src/rules/__tests__/no-state-without-component.js b/packages/stylelint-config-swissquote/src/rules/__tests__/no-state-without-component.js index 2c138394f..f6620c786 100644 --- a/packages/stylelint-config-swissquote/src/rules/__tests__/no-state-without-component.js +++ b/packages/stylelint-config-swissquote/src/rules/__tests__/no-state-without-component.js @@ -1,5 +1,6 @@ -const testRule = require("../../testUtils/ruleTester"); -const { ruleName, messages } = require("../no-state-without-component"); +import testRule from "../../testUtils/ruleTester.js"; +import rule from "../no-state-without-component.js"; +const { ruleName, messages } = rule; testRule({ plugins: ["./index.js"], diff --git a/packages/stylelint-config-swissquote/src/rules/__tests__/no-type-outside-scope.js b/packages/stylelint-config-swissquote/src/rules/__tests__/no-type-outside-scope.js index cb2d334ce..8160c1d73 100644 --- a/packages/stylelint-config-swissquote/src/rules/__tests__/no-type-outside-scope.js +++ b/packages/stylelint-config-swissquote/src/rules/__tests__/no-type-outside-scope.js @@ -1,5 +1,6 @@ -const testRule = require("../../testUtils/ruleTester"); -const { ruleName, messages } = require("../no-type-outside-scope"); +import testRule from "../../testUtils/ruleTester.js"; +import rule from "../no-type-outside-scope.js"; +const { ruleName, messages } = rule; testRule({ plugins: ["./index.js"], diff --git a/packages/stylelint-config-swissquote/src/rules/__tests__/no-utility-reassignment.js b/packages/stylelint-config-swissquote/src/rules/__tests__/no-utility-reassignment.js index fa3d8437b..fc1a09522 100644 --- a/packages/stylelint-config-swissquote/src/rules/__tests__/no-utility-reassignment.js +++ b/packages/stylelint-config-swissquote/src/rules/__tests__/no-utility-reassignment.js @@ -1,5 +1,6 @@ -const testRule = require("../../testUtils/ruleTester"); -const { ruleName, messages } = require("../no-utility-reassignment"); +import testRule from "../../testUtils/ruleTester.js"; +import rule from "../no-utility-reassignment.js"; +const { ruleName, messages } = rule; testRule({ plugins: ["./index.js"], diff --git a/packages/stylelint-config-swissquote/src/rules/__tests__/no-variable-in-transpiled-function.js b/packages/stylelint-config-swissquote/src/rules/__tests__/no-variable-in-transpiled-function.js index 0c907ddcb..cb9bc8050 100644 --- a/packages/stylelint-config-swissquote/src/rules/__tests__/no-variable-in-transpiled-function.js +++ b/packages/stylelint-config-swissquote/src/rules/__tests__/no-variable-in-transpiled-function.js @@ -1,5 +1,6 @@ -const testRule = require("../../testUtils/ruleTester"); -const { ruleName } = require("../no-variable-in-transpiled-function"); +import testRule from "../../testUtils/ruleTester.js"; +import rule from "../no-variable-in-transpiled-function.js"; +const { ruleName } = rule; // no warnings for browers that transpile variables testRule({ diff --git a/packages/stylelint-config-swissquote/src/rules/no-block-inside-block.js b/packages/stylelint-config-swissquote/src/rules/no-block-inside-block.js index c5e359ef9..6cb142b6f 100644 --- a/packages/stylelint-config-swissquote/src/rules/no-block-inside-block.js +++ b/packages/stylelint-config-swissquote/src/rules/no-block-inside-block.js @@ -1,9 +1,9 @@ -const stylelint = require("../../shims/stylelint"); +import stylelint from "stylelint"; -const selectorParser = require("../../packages/postcss-selector-parser"); -const resolveNestedSelector = require("../../packages/postcss-resolve-nested-selector"); +import selectorParser from "postcss-selector-parser"; +import resolveNestedSelector from "postcss-resolve-nested-selector"; -const cssRuleHasSelectorEndingWithColon = require("../utils/cssRuleHasSelectorEndingWithColon"); +import cssRuleHasSelectorEndingWithColon from "../utils/cssRuleHasSelectorEndingWithColon.js"; const ruleName = "swissquote/no-block-inside-block"; const messages = { @@ -46,7 +46,7 @@ function isInsideBlock(selectorNode) { ); } -module.exports = function() { +const rule = function() { return (root, result) => { root.walkRules(rule => { if (cssRuleHasSelectorEndingWithColon(rule)) { @@ -79,5 +79,6 @@ module.exports = function() { }; }; -module.exports.ruleName = ruleName; -module.exports.messages = messages; +rule.ruleName = ruleName; +rule.messages = messages; +export default rule; diff --git a/packages/stylelint-config-swissquote/src/rules/no-hack-reassignment.js b/packages/stylelint-config-swissquote/src/rules/no-hack-reassignment.js index 78816f077..7d5c0e3d0 100644 --- a/packages/stylelint-config-swissquote/src/rules/no-hack-reassignment.js +++ b/packages/stylelint-config-swissquote/src/rules/no-hack-reassignment.js @@ -1,9 +1,9 @@ -const stylelint = require("../../shims/stylelint"); +import stylelint from "stylelint"; -const selectorParser = require("../../packages/postcss-selector-parser"); -const resolveNestedSelector = require("../../packages/postcss-resolve-nested-selector"); +import selectorParser from "postcss-selector-parser"; +import resolveNestedSelector from "postcss-resolve-nested-selector"; -const cssRuleHasSelectorEndingWithColon = require("../utils/cssRuleHasSelectorEndingWithColon"); +import cssRuleHasSelectorEndingWithColon from "../utils/cssRuleHasSelectorEndingWithColon.js"; const ruleName = "swissquote/no-hack-reassignment"; const messages = { @@ -12,7 +12,7 @@ const messages = { const isHack = /^_/; -module.exports = function(/*mainOption, moreOptions*/) { +const rule = function(/*mainOption, moreOptions*/) { return (root, result) => { root.walkRules(rule => { if (cssRuleHasSelectorEndingWithColon(rule)) { @@ -45,6 +45,6 @@ module.exports = function(/*mainOption, moreOptions*/) { }; }; -module.exports.ruleName = ruleName; - -module.exports.messages = messages; +rule.ruleName = ruleName; +rule.messages = messages; +export default rule; diff --git a/packages/stylelint-config-swissquote/src/rules/no-negative-var.js b/packages/stylelint-config-swissquote/src/rules/no-negative-var.js index 0bbc2a306..eec7e8072 100644 --- a/packages/stylelint-config-swissquote/src/rules/no-negative-var.js +++ b/packages/stylelint-config-swissquote/src/rules/no-negative-var.js @@ -1,8 +1,8 @@ -const stylelint = require("../../shims/stylelint"); +import stylelint from "stylelint"; -const declarationValueIndex = require("../../dist/stylelint-utils/stylelint-declarationValueIndex"); -const isStandardSyntaxFunction = require("../../dist/stylelint-utils/stylelint-isStandardSyntaxFunction"); -const valueParser = require("../../packages/postcss-value-parser"); +import declarationValueIndex from "stylelint/lib/utils/declarationValueIndex.mjs"; +import isStandardSyntaxFunction from "stylelint/lib/utils/isStandardSyntaxFunction.mjs"; +import valueParser from "postcss-value-parser"; const ruleName = "swissquote/no-negative-var"; @@ -12,7 +12,7 @@ const messages = { const negativeVar = "-var"; -module.exports = function() { +const rule = function() { return (root, result) => { root.walkDecls(decl => { const value = decl.value; @@ -43,5 +43,6 @@ module.exports = function() { }; }; -module.exports.ruleName = ruleName; -module.exports.messages = messages; +rule.ruleName = ruleName; +rule.messages = messages; +export default rule; diff --git a/packages/stylelint-config-swissquote/src/rules/no-state-without-component.js b/packages/stylelint-config-swissquote/src/rules/no-state-without-component.js index 7f5623921..8ac67c27e 100644 --- a/packages/stylelint-config-swissquote/src/rules/no-state-without-component.js +++ b/packages/stylelint-config-swissquote/src/rules/no-state-without-component.js @@ -1,9 +1,9 @@ -const stylelint = require("../../shims/stylelint"); +import stylelint from "stylelint"; -const selectorParser = require("../../packages/postcss-selector-parser"); -const resolveNestedSelector = require("../../packages/postcss-resolve-nested-selector"); +import selectorParser from "postcss-selector-parser"; +import resolveNestedSelector from "postcss-resolve-nested-selector"; -const cssRuleHasSelectorEndingWithColon = require("../utils/cssRuleHasSelectorEndingWithColon"); +import cssRuleHasSelectorEndingWithColon from "../utils/cssRuleHasSelectorEndingWithColon.js"; const ruleName = "swissquote/no-state-without-component"; const messages = { @@ -68,7 +68,7 @@ function isOrphanState(selectorNode) { ); } -module.exports = function() { +const rule = function() { return (root, result) => { root.walkRules(rule => { if (cssRuleHasSelectorEndingWithColon(rule)) { @@ -102,5 +102,6 @@ module.exports = function() { }; }; -module.exports.ruleName = ruleName; -module.exports.messages = messages; +rule.ruleName = ruleName; +rule.messages = messages; +export default rule; diff --git a/packages/stylelint-config-swissquote/src/rules/no-type-outside-scope.js b/packages/stylelint-config-swissquote/src/rules/no-type-outside-scope.js index 75a44c4d0..0382b6c44 100644 --- a/packages/stylelint-config-swissquote/src/rules/no-type-outside-scope.js +++ b/packages/stylelint-config-swissquote/src/rules/no-type-outside-scope.js @@ -1,11 +1,9 @@ -const stylelint = require("../../shims/stylelint"); - -const isKeyframeSelector = require("../../dist/stylelint-utils/stylelint-isKeyframeSelector"); -const isStandardSyntaxRule = require("../../dist/stylelint-utils/stylelint-isStandardSyntaxRule"); -const isStandardSyntaxSelector = require("../../dist/stylelint-utils/stylelint-isStandardSyntaxSelector"); - -const resolveNestedSelector = require("../utils/resolveNestedSelector"); -const parseSelector = require("../utils/parseSelector"); +import stylelint from "stylelint"; +import isKeyframeSelector from "stylelint/lib/utils/isKeyframeSelector.mjs"; +import isStandardSyntaxRule from "stylelint/lib/utils/isStandardSyntaxRule.mjs"; +import isStandardSyntaxSelector from "stylelint/lib/utils/isStandardSyntaxSelector.mjs"; +import resolveNestedSelector from "../utils/resolveNestedSelector.js"; +import parseSelector from "../utils/parseSelector.js"; const ruleName = "swissquote/no-type-outside-scope"; @@ -71,7 +69,7 @@ function checkSelector(selectorNode, ruleNode, result) { } } -module.exports = function() { +const rule = function() { return (root, result) => { root.walkRules(rule => { if ( @@ -111,5 +109,6 @@ module.exports = function() { }; }; -module.exports.ruleName = ruleName; -module.exports.messages = messages; +rule.ruleName = ruleName; +rule.messages = messages; +export default rule; diff --git a/packages/stylelint-config-swissquote/src/rules/no-utility-reassignment.js b/packages/stylelint-config-swissquote/src/rules/no-utility-reassignment.js index 71d16f3f7..34f4a4a94 100644 --- a/packages/stylelint-config-swissquote/src/rules/no-utility-reassignment.js +++ b/packages/stylelint-config-swissquote/src/rules/no-utility-reassignment.js @@ -1,9 +1,9 @@ -const stylelint = require("../../shims/stylelint"); +import stylelint from "stylelint"; -const selectorParser = require("../../packages/postcss-selector-parser"); -const resolveNestedSelector = require("../../packages/postcss-resolve-nested-selector"); +import selectorParser from "postcss-selector-parser"; +import resolveNestedSelector from "postcss-resolve-nested-selector"; -const cssRuleHasSelectorEndingWithColon = require("../utils/cssRuleHasSelectorEndingWithColon"); +import cssRuleHasSelectorEndingWithColon from "../utils/cssRuleHasSelectorEndingWithColon.js"; const ruleName = "swissquote/no-utility-reassignment"; const messages = { @@ -12,7 +12,7 @@ const messages = { const isUtility = /^u-/; -module.exports = function(/*mainOption, moreOptions*/) { +const rule = function(/*mainOption, moreOptions*/) { return (root, result) => { root.walkRules(rule => { if (cssRuleHasSelectorEndingWithColon(rule)) { @@ -45,5 +45,6 @@ module.exports = function(/*mainOption, moreOptions*/) { }; }; -module.exports.ruleName = ruleName; -module.exports.messages = messages; +rule.ruleName = ruleName; +rule.messages = messages; +export default rule; diff --git a/packages/stylelint-config-swissquote/src/rules/no-variable-in-transpiled-function.js b/packages/stylelint-config-swissquote/src/rules/no-variable-in-transpiled-function.js index 426ee34fc..1c8314e13 100644 --- a/packages/stylelint-config-swissquote/src/rules/no-variable-in-transpiled-function.js +++ b/packages/stylelint-config-swissquote/src/rules/no-variable-in-transpiled-function.js @@ -1,9 +1,12 @@ -const stylelint = require("../../shims/stylelint"); -const browserslist = require("@swissquote/crafty-commons/packages/browserslist"); +import { createRequire } from "node:module"; +import stylelint from "stylelint"; +import browserslist from "@swissquote/crafty-commons/packages/browserslist.js"; -const valueParser = require("../../packages/postcss-value-parser"); -const declarationValueIndex = require("../../dist/stylelint-utils/stylelint-declarationValueIndex"); -const isStandardSyntaxFunction = require("../../dist/stylelint-utils/stylelint-isStandardSyntaxFunction"); +import valueParser from "postcss-value-parser"; +import declarationValueIndex from "stylelint/lib/utils/declarationValueIndex.mjs"; +import isStandardSyntaxFunction from "stylelint/lib/utils/isStandardSyntaxFunction.mjs"; + +const require = createRequire(import.meta.url); const w3cColorFunction = /^(srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65)$/; @@ -140,7 +143,7 @@ function isUnsupportedFunction(node, browsers) { return false; } -module.exports = (on, options) => { +const rule = (on, options) => { return (root, result) => { const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual: options, @@ -192,5 +195,6 @@ module.exports = (on, options) => { }; }; -module.exports.ruleName = ruleName; -module.exports.messages = messages; +rule.ruleName = ruleName; +rule.messages = messages; +export default rule; diff --git a/packages/stylelint-config-swissquote/src/testUtils/ruleTester.js b/packages/stylelint-config-swissquote/src/testUtils/ruleTester.js index f244ccf1b..f93284887 100644 --- a/packages/stylelint-config-swissquote/src/testUtils/ruleTester.js +++ b/packages/stylelint-config-swissquote/src/testUtils/ruleTester.js @@ -1,6 +1,8 @@ -const test = require("ava"); -const util = require("util"); -const { lint } = require("stylelint"); +import test from "ava"; +import util from "util"; +import stylelint from "stylelint"; + +const { lint } = stylelint; function setupTestCases({ name, cases, schema, comparisons }) { if (cases && cases.length) { @@ -24,7 +26,7 @@ function setupTestCases({ name, cases, schema, comparisons }) { } } -module.exports = function testRule(schema) { +export default function testRule(schema) { const stylelintConfig = { plugins: schema.plugins, rules: { diff --git a/packages/stylelint-config-swissquote/src/utils/__tests__/resolveNestedSelector.js b/packages/stylelint-config-swissquote/src/utils/__tests__/resolveNestedSelector.js index 573b0efed..82566f2a1 100644 --- a/packages/stylelint-config-swissquote/src/utils/__tests__/resolveNestedSelector.js +++ b/packages/stylelint-config-swissquote/src/utils/__tests__/resolveNestedSelector.js @@ -1,12 +1,13 @@ -const test = require("ava"); +import test from "ava"; -const isKeyframeSelector = require("../../../dist/stylelint-utils/stylelint-isKeyframeSelector"); -const isStandardSyntaxRule = require("../../../dist/stylelint-utils/stylelint-isStandardSyntaxRule"); -const isStandardSyntaxSelector = require("../../../dist/stylelint-utils/stylelint-isStandardSyntaxSelector"); -const postcss = require("postcss"); -const scssSyntax = require("postcss-scss"); +import isKeyframeSelector from "stylelint/lib/utils/isKeyframeSelector.mjs"; +import isStandardSyntaxRule from "stylelint/lib/utils/isStandardSyntaxRule.mjs"; +import isStandardSyntaxSelector from "stylelint/lib/utils/isStandardSyntaxSelector.mjs"; -const resolveNestedSelector = require("../resolveNestedSelector"); +import postcss from "postcss"; +import scssSyntax from "postcss-scss"; + +import resolveNestedSelector from "../resolveNestedSelector.js"; function getResolvedSelectors(results) { return root => { diff --git a/packages/stylelint-config-swissquote/src/utils/cssRuleHasSelectorEndingWithColon.js b/packages/stylelint-config-swissquote/src/utils/cssRuleHasSelectorEndingWithColon.js index fcbd43540..1dc90bb51 100644 --- a/packages/stylelint-config-swissquote/src/utils/cssRuleHasSelectorEndingWithColon.js +++ b/packages/stylelint-config-swissquote/src/utils/cssRuleHasSelectorEndingWithColon.js @@ -6,7 +6,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty; * @param {Rule} rule postcss rule node * @return {boolean} If `true`, the rule has a selector ending in a colon */ -module.exports = function(rule) { +export default function(rule) { const selector = (hasOwnProperty.call(rule, "raws") && hasOwnProperty.call(rule.raws, "selector") && diff --git a/packages/stylelint-config-swissquote/src/utils/parseSelector.js b/packages/stylelint-config-swissquote/src/utils/parseSelector.js index 0162231b3..5235240a5 100644 --- a/packages/stylelint-config-swissquote/src/utils/parseSelector.js +++ b/packages/stylelint-config-swissquote/src/utils/parseSelector.js @@ -1,6 +1,6 @@ -const selectorParser = require("../../packages/postcss-selector-parser"); +import selectorParser from "postcss-selector-parser"; -function parseSelector(resolvedSelector) { +export default function parseSelector(resolvedSelector) { const container = selectorParser.selector(); for (const part of resolvedSelector) { const parsed = selectorParser().astSync(part.selector); @@ -15,5 +15,3 @@ function parseSelector(resolvedSelector) { return root; } - -module.exports = parseSelector; diff --git a/packages/stylelint-config-swissquote/src/utils/resolveNestedSelector.js b/packages/stylelint-config-swissquote/src/utils/resolveNestedSelector.js index 622bef9e6..1fe5d9d6f 100644 --- a/packages/stylelint-config-swissquote/src/utils/resolveNestedSelector.js +++ b/packages/stylelint-config-swissquote/src/utils/resolveNestedSelector.js @@ -71,7 +71,7 @@ function insertParent(initialParentSelector, initialSelector) { throw new Error("How did you get here ?"); } -function resolveNestedSelector(initialSelector, node) { +export default function resolveNestedSelector(initialSelector, node) { const parent = node.parent; const selector = Array.isArray(initialSelector) @@ -110,4 +110,3 @@ function resolveNestedSelector(initialSelector, node) { }, []); } -module.exports = resolveNestedSelector;