From 031d1afdafd8208e5803b1257a1e8eb9b527dce5 Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Wed, 22 Nov 2023 14:36:27 -0300 Subject: [PATCH 1/9] feat(stylelint): add @vtex/shoreline-stylelint package --- packages/stylelint/CHANGELOG.md | 4 ++ packages/stylelint/package.json | 48 +++++++++++++ packages/stylelint/src/index.js | 29 ++++++++ packages/stylelint/src/index.types.d.ts | 2 + .../src/plugins/no-space-px-values/index.js | 67 +++++++++++++++++++ .../plugins/no-space-px-values/index.test.js | 43 ++++++++++++ .../src/plugins/no-text-property/index.js | 62 +++++++++++++++++ .../plugins/no-text-property/index.test.js | 39 +++++++++++ .../src/utils/replace-declaration.mjs | 13 ++++ packages/stylelint/tsconfig.json | 17 +++++ packages/stylelint/tsup.config.ts | 11 +++ 11 files changed, 335 insertions(+) create mode 100644 packages/stylelint/CHANGELOG.md create mode 100644 packages/stylelint/package.json create mode 100644 packages/stylelint/src/index.js create mode 100644 packages/stylelint/src/index.types.d.ts create mode 100644 packages/stylelint/src/plugins/no-space-px-values/index.js create mode 100644 packages/stylelint/src/plugins/no-space-px-values/index.test.js create mode 100644 packages/stylelint/src/plugins/no-text-property/index.js create mode 100644 packages/stylelint/src/plugins/no-text-property/index.test.js create mode 100644 packages/stylelint/src/utils/replace-declaration.mjs create mode 100644 packages/stylelint/tsconfig.json create mode 100644 packages/stylelint/tsup.config.ts diff --git a/packages/stylelint/CHANGELOG.md b/packages/stylelint/CHANGELOG.md new file mode 100644 index 0000000000..e4d87c4d45 --- /dev/null +++ b/packages/stylelint/CHANGELOG.md @@ -0,0 +1,4 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. diff --git a/packages/stylelint/package.json b/packages/stylelint/package.json new file mode 100644 index 0000000000..e2b783ecee --- /dev/null +++ b/packages/stylelint/package.json @@ -0,0 +1,48 @@ +{ + "name": "@vtex/shoreline-stylelint", + "version": "0.0.0", + "main": "./dist/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/index.d.ts", + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org" + }, + "files": [ + "dist" + ], + "exports": { + ".": { + "require": "./dist/index.js", + "import": "./dist/esm/index.js", + "types": "./dist/index.d.ts" + } + }, + "engines": { + "node": ">=16" + }, + "scripts": { + "prebuild": "rm -rf dist", + "dev": "tsup --watch", + "build": "npm run prebuild && tsup", + "test": "jest" + }, + "repository": { + "directory": "packages/stylelint", + "type": "git", + "url": "git+https://github.com/vtex/shoreline.git" + }, + "bugs": { + "url": "https://github.com/vtex/shoreline/issues" + }, + "peerDependencies": { + "stylelint": "^14.15.0 || ^15.0.0" + }, + "devDependencies": { + "tsup": "7.2.0" + }, + "dependencies": {}, + "jest": { + "preset": "jest-preset-stylelint" + } +} diff --git a/packages/stylelint/src/index.js b/packages/stylelint/src/index.js new file mode 100644 index 0000000000..b2855d14c8 --- /dev/null +++ b/packages/stylelint/src/index.js @@ -0,0 +1,29 @@ +'use strict' + +const textPlugin = require('./plugins/no-text-property') +const spacePlugin = require('./plugins/no-space-px-values') + +const colorRules = { + 'color-no-invalid-hex': [ + true, + { + message: 'Please use a Shoreline color token instead of %s', + }, + ], +} + +const typographyRules = { + 'shoreline/no-text-property': true, +} + +const spaceRules = { + 'shoreline/no-space-px-values': true, +} + +module.exports = { + plugins: [textPlugin, spacePlugin], + reportDescriptionlessDisables: true, + reportNeedlessDisables: true, + reportInvalidScopeDisables: true, + rules: { ...colorRules, ...typographyRules, ...spaceRules }, +} diff --git a/packages/stylelint/src/index.types.d.ts b/packages/stylelint/src/index.types.d.ts new file mode 100644 index 0000000000..de5aae157d --- /dev/null +++ b/packages/stylelint/src/index.types.d.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line @typescript-eslint/consistent-type-imports +declare let testRule: import('jest-preset-stylelint').TestRule diff --git a/packages/stylelint/src/plugins/no-space-px-values/index.js b/packages/stylelint/src/plugins/no-space-px-values/index.js new file mode 100644 index 0000000000..ce51089497 --- /dev/null +++ b/packages/stylelint/src/plugins/no-space-px-values/index.js @@ -0,0 +1,67 @@ +const stylelint = require('stylelint') +const { replaceDeclaration } = require('../../utils/replace-declaration.mjs') + +const { ruleMessages, validateOptions, report } = stylelint.utils + +const ruleName = 'shoreline/no-space-px-values' +const messages = ruleMessages(ruleName, { + expected: (prop, value, expectedValue) => + `Expected "${prop}: ${value}" to be "${prop}: ${expectedValue}".`, +}) + +const spaceProps = [ + 'margin', + 'margin-left', + 'margin-right', + 'margin-top', + 'margin-bottom', + 'padding', + 'padding-left', + 'padding-right', + 'padding-top', + 'padding-bottom', +] + +module.exports = stylelint.createPlugin( + ruleName, + function ruleFunction(primaryOption, secondaryOptionObject, context) { + return function lint(postcssRoot, postcssResult) { + const validOptions = validateOptions(postcssResult, ruleName, { + // No options for now... + }) + + if (!validOptions) return + + const isAutoFixing = Boolean(context.fix) + + postcssRoot.walkDecls((decl) => { + const isSpaceProp = spaceProps.includes(decl.prop) + + const isInvalid = isSpaceProp && decl.value.includes('px') + + if (!isInvalid) return + + const pxUnits = decl.value.split('px').filter((unit) => !!unit) + + const remUnits = pxUnits + .map((unit) => `${Number(unit.trim()) / 16}rem`) + .join(' ') + + if (isAutoFixing) { + replaceDeclaration(decl, remUnits) + } else { + report({ + ruleName, + result: postcssResult, + message: messages.expected(decl.prop, decl.value, remUnits), + node: decl, + word: 'text:', + }) + } + }) + } + } +) + +module.exports.ruleName = ruleName +module.exports.messages = messages diff --git a/packages/stylelint/src/plugins/no-space-px-values/index.test.js b/packages/stylelint/src/plugins/no-space-px-values/index.test.js new file mode 100644 index 0000000000..b3d3bfce9b --- /dev/null +++ b/packages/stylelint/src/plugins/no-space-px-values/index.test.js @@ -0,0 +1,43 @@ +const { ruleName, messages } = require('.') + +// eslint-disable-next-line no-undef +testRule({ + fix: true, + ruleName, + plugins: [__dirname], + config: {}, + accept: [ + { + code: 'margin: 1rem', + description: 'Defining a margin', + }, + { + code: 'padding: 1rem 0.5rem', + description: 'Defining a padding', + }, + { + code: 'padding-left: 1rem', + description: 'Defining a padding-left', + }, + ], + reject: [ + { + code: 'margin: 16px', + fixed: 'margin: 1rem', + description: 'Defining a margin', + message: messages.expected('margin', '16px', '1rem'), + }, + { + code: 'padding: 16px 8px', + description: 'Defining a padding', + fixed: 'padding: 1rem 0.5rem', + message: messages.expected('padding', '16px 8px', '1rem 0.5rem'), + }, + { + code: 'padding-left: 22px', + description: 'Defining a padding-left', + fixed: 'padding-left: 1.375rem', + message: messages.expected('padding-left', '22px', '1.375rem'), + }, + ], +}) diff --git a/packages/stylelint/src/plugins/no-text-property/index.js b/packages/stylelint/src/plugins/no-text-property/index.js new file mode 100644 index 0000000000..4d91890444 --- /dev/null +++ b/packages/stylelint/src/plugins/no-text-property/index.js @@ -0,0 +1,62 @@ +const stylelint = require('stylelint') +const { replaceDeclaration } = require('../../utils/replace-declaration.mjs') + +const { ruleMessages, validateOptions, report } = stylelint.utils + +const ruleName = 'shoreline/no-text-property' +const messages = ruleMessages(ruleName, { + expected: `Expected "text" property to be splited in "font" and "letter-spacing"`, +}) + +const textTokenPrefix = '--sl-text' + +module.exports = stylelint.createPlugin( + ruleName, + function ruleFunction(primaryOption, secondaryOptionObject, context) { + return function lint(postcssRoot, postcssResult) { + const validOptions = validateOptions(postcssResult, ruleName, { + // No options for now... + }) + + if (!validOptions) return + + const isAutoFixing = Boolean(context.fix) + + postcssRoot.walkDecls((decl) => { + const isTextProp = decl.prop === 'text' + + if (!isTextProp) return + + if (isAutoFixing) { + const hasShorelinePrefix = decl.value.includes(textTokenPrefix) + + const newFontValue = hasShorelinePrefix + ? decl.value.replace(')', '-font)') + : decl.value + + const newLetterSpacingValue = hasShorelinePrefix + ? newFontValue.replace('font', 'letter-spacing') + : decl.value + + replaceDeclaration(decl, newFontValue, 'font') + + decl.cloneAfter({ + prop: 'letter-spacing', + value: newLetterSpacingValue, + }) + } else { + report({ + ruleName, + result: postcssResult, + message: messages.expected, + node: decl, + word: 'text:', + }) + } + }) + } + } +) + +module.exports.ruleName = ruleName +module.exports.messages = messages diff --git a/packages/stylelint/src/plugins/no-text-property/index.test.js b/packages/stylelint/src/plugins/no-text-property/index.test.js new file mode 100644 index 0000000000..73db2cfcc0 --- /dev/null +++ b/packages/stylelint/src/plugins/no-text-property/index.test.js @@ -0,0 +1,39 @@ +const { ruleName, messages } = require('.') + +// eslint-disable-next-line no-undef +testRule({ + fix: true, + ruleName, + plugins: [__dirname], + config: {}, + accept: [ + { + code: 'font: var(--sl-text-body-font)', + description: 'Defining a font', + }, + { + code: 'letter-spacing: var(--sl-text-body-letter-spacing)', + description: 'Defining a letter-spacing', + }, + ], + reject: [ + { + code: `text: var(--sl-text-body)`, + fixed: `font: var(--sl-text-body-font);letter-spacing: var(--sl-text-body-letter-spacing)`, + description: 'Defining a text rule', + message: messages.expected, + }, + { + code: `text: test`, + fixed: `font: test;letter-spacing: test`, + description: 'Defining a disallowed include name with a namespace', + message: messages.expected, + }, + { + code: `text: var(--sl-my-custom-text-token)`, + fixed: `font: var(--sl-my-custom-text-token);letter-spacing: var(--sl-my-custom-text-token)`, + description: 'Defining a disallowed include name with a namespace', + message: messages.expected, + }, + ], +}) diff --git a/packages/stylelint/src/utils/replace-declaration.mjs b/packages/stylelint/src/utils/replace-declaration.mjs new file mode 100644 index 0000000000..a8082057c5 --- /dev/null +++ b/packages/stylelint/src/utils/replace-declaration.mjs @@ -0,0 +1,13 @@ +function replaceDeclaration(declaration, newValue, newProp) { + if (declaration.raws.value) { + declaration.raws.prop.raw = newProp || declaration.prop + declaration.raws.value.raw = newValue + } else { + declaration.prop = newProp || declaration.prop + declaration.value = newValue + } +} + +module.exports = { + replaceDeclaration, +} diff --git a/packages/stylelint/tsconfig.json b/packages/stylelint/tsconfig.json new file mode 100644 index 0000000000..e89d51e831 --- /dev/null +++ b/packages/stylelint/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "allowJs": true, + "rootDir": "./src", + "module": "commonjs", + "moduleResolution": "node" + }, + "include": ["./src"], + "exclude": [ + "node_modules", + "dist", + "**/*.test.*", + "**/*.stories.*", + "**/*test-utils*" + ] +} diff --git a/packages/stylelint/tsup.config.ts b/packages/stylelint/tsup.config.ts new file mode 100644 index 0000000000..98d57d9974 --- /dev/null +++ b/packages/stylelint/tsup.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from 'tsup' + +export default defineConfig({ + entry: ['src/index.js'], + format: ['cjs', 'esm'], + splitting: false, + sourcemap: true, + clean: true, + dts: true, + legacyOutput: true, +}) From 5f6e3459ad72b4d527e67203b9d57550ee1e5f09 Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Wed, 22 Nov 2023 14:37:07 -0300 Subject: [PATCH 2/9] feat(stylelint): add @vtex/shoreline-stylelint configuration --- .stylelintignore | 25 +++++++++++ .stylelintrc.js | 9 ++++ package.json | 6 ++- pnpm-lock.yaml | 112 ++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 .stylelintignore create mode 100644 .stylelintrc.js diff --git a/.stylelintignore b/.stylelintignore new file mode 100644 index 0000000000..0e2a7c1f3d --- /dev/null +++ b/.stylelintignore @@ -0,0 +1,25 @@ +# Keep in sync with .gitignore + .prettierignore +**/node_modules +**/dist +packages/icons/native +packages/admin-ui-docs +packages/next-docs +**/.cache +**/coverage +**/build +storybook-static +**/*.stories.ts + +# Resolve: Parsing error: Unexpected token < +**/gatsby-browser.js +**/gatsby-ssr.js +**/404.js +**/src/theme/**/*.js + +# Resolve: Parsing error: Unexpected token . +# not accepting conditional chaining +packages/admin-ui-codemod/src/space-tokens-review.js +packages/create-raccoon-app/src/index.js + +# Resolve: Expected exception block, space or tab after '//' in comment +examples/shoreline-nextjs-integration/next-env.d.ts \ No newline at end of file diff --git a/.stylelintrc.js b/.stylelintrc.js new file mode 100644 index 0000000000..b7b93a0d4d --- /dev/null +++ b/.stylelintrc.js @@ -0,0 +1,9 @@ +module.exports = { + extends: ['@vtex/shoreline-stylelint'], + plugins: ['stylelint-prettier'], + files: ['**/*.css'], + reportDescriptionlessDisables: true, + reportNeedlessDisables: true, + reportInvalidScopeDisables: true, + rules: {}, +} diff --git a/package.json b/package.json index eabae232c3..a157d2ea87 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "clean": "pnpm turbo clean && turbo run clean", "format": "prettier --write \"packages/**/*.{ts,js,tsx,jsx,json}\" \"examples/**/*.{ts,js,tsx,jsx,json}\"", "lint": "eslint --ext .ts,.tsx,.js,.jsx \"packages/**/*.{ts,js,tsx,jsx}\" \"examples/**/*.{ts,js,tsx,jsx}\"", + "lint:css": "stylelint '**/*.css'", "build-storybook": "storybook build", "dev-storybook": "pnpm storybook dev -p 6006", "build:storybook": "pnpm build && pnpm storybook build", @@ -89,7 +90,10 @@ "url-loader": "^4.1.0", "vite": "5.0.2", "vitest": "0.34.6", - "tsup": "8.0.1" + "tsup": "8.0.1", + "stylelint": "^15.11.0", + "stylelint-prettier": "^4.0.2", + "@vtex/shoreline-stylelint": "workspace" }, "lint-staged": { "*.{ts,tsx,js,jsx}": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69af4f0938..45636da1c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -67,9 +67,15 @@ importers: '@vtex/prettier-config': specifier: ^0.3.1 version: 0.3.6(prettier@2.8.8) +<<<<<<< HEAD '@vtex/shoreline-test-utils': specifier: workspace:* version: link:packages/test-utils +======= + '@vtex/shoreline-stylelint': + specifier: workspace + version: link:packages/stylelint +>>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) '@vtex/tsconfig': specifier: ^0.5.6 version: 0.5.6(typescript@4.9.5) @@ -103,6 +109,24 @@ importers: husky: specifier: ^8.0.3 version: 8.0.3 +<<<<<<< HEAD +======= + jest: + specifier: 29.6.2 + version: 29.6.2(@types/node@20.4.5)(babel-plugin-macros@3.1.0) + jest-axe: + specifier: 8.0.0 + version: 8.0.0 + jest-environment-jsdom: + specifier: 29.6.2 + version: 29.6.2 + jest-preset-stylelint: + specifier: ^6.3.2 + version: 6.3.2(jest@29.6.2) + jest-watch-typeahead: + specifier: 2.2.2 + version: 2.2.2(jest@29.6.2) +>>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) jsdom: specifier: 23.0.0 version: 23.0.0 @@ -136,6 +160,12 @@ importers: storybook: specifier: ^7.5.3 version: 7.5.3 + stylelint: + specifier: ^15.11.0 + version: 15.11.0 + stylelint-prettier: + specifier: ^4.0.2 + version: 4.0.2(prettier@2.8.8)(stylelint@15.11.0) tslib: specifier: 2.6.2 version: 2.6.2 @@ -397,6 +427,7 @@ importers: specifier: ^0.5.0 version: link:../utils +<<<<<<< HEAD packages/test-utils: dependencies: '@testing-library/dom': @@ -412,6 +443,17 @@ importers: vitest: specifier: 0.34.6 version: 0.34.6(jsdom@23.0.0) +======= + packages/stylelint: + dependencies: + stylelint: + specifier: ^14.15.0 || ^15.0.0 + version: 15.11.0 + devDependencies: + tsup: + specifier: 7.2.0 + version: 7.2.0(@swc/core@1.2.241)(postcss@8.4.31)(typescript@4.9.5) +>>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) packages/theme: dependencies: @@ -11711,6 +11753,10 @@ packages: tslib: 2.6.2 dev: true + /astral-regex@2.0.0: + resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==} + engines: {node: '>=8'} + /astring@1.8.6: resolution: { @@ -13512,7 +13558,6 @@ packages: js-yaml: 4.1.0 parse-json: 5.2.0 path-type: 4.0.0 - dev: true /create-require@1.1.1: resolution: @@ -14238,6 +14283,10 @@ packages: engines: { node: '>=0.10.0' } dev: true + /decamelize@5.0.1: + resolution: {integrity: sha512-VfxadyCECXgQlkoEAjeghAr5gY3Hf+IKjKb+X8tGVDtveCjN+USwprd2q3QXBR9T1+x2DG0XZF5/w+7HAtSaXA==} + engines: {node: '>=10'} + /decimal.js@10.4.3: resolution: { @@ -16329,6 +16378,10 @@ packages: } dev: true + /fastest-levenshtein@1.0.16: + resolution: {integrity: sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg==} + engines: {node: '>= 4.9.1'} + /fastq@1.13.0: resolution: { @@ -17856,7 +17909,6 @@ packages: engines: { node: '>=10' } dependencies: lru-cache: 6.0.0 - dev: true /hosted-git-info@6.1.1: resolution: @@ -19165,6 +19217,15 @@ packages: fsevents: 2.3.3 dev: true + /jest-preset-stylelint@6.3.2(jest@29.6.2): + resolution: {integrity: sha512-OnodJG8lMAzvhx5WjcGdne6TnGSWASlcUySd3sY+4E3Adgv4LcxBaNT6E15u5WTPpDsElaJqYNveANf2htR/Ng==} + engines: {node: ^14.15.0 || >=16.10.0} + peerDependencies: + jest: ^29.0.2 + dependencies: + jest: 29.6.2(@types/node@20.4.5)(babel-plugin-macros@3.1.0) + dev: true + /jest-regex-util@29.4.3: resolution: { @@ -19549,6 +19610,9 @@ packages: engines: { node: '>=6' } dev: false + /known-css-properties@0.29.0: + resolution: {integrity: sha512-Ne7wqW7/9Cz54PDt4I3tcV+hAyat8ypyOGzYRJQfdxnnjeWsTxt1cy8pjvvKeI5kfXuyvULyeeAvwvvtAX3ayQ==} + /language-subtag-registry@0.3.22: resolution: { @@ -21446,7 +21510,6 @@ packages: arrify: 1.0.1 is-plain-obj: 1.1.0 kind-of: 6.0.3 - dev: true /minimist@1.2.6: resolution: @@ -22196,7 +22259,6 @@ packages: is-core-module: 2.12.1 semver: 7.5.4 validate-npm-package-license: 3.0.4 - dev: true /normalize-package-data@5.0.0: resolution: @@ -24907,6 +24969,14 @@ packages: type-fest: 0.8.1 dev: true + /read-pkg-up@8.0.0: + resolution: {integrity: sha512-snVCqPczksT0HS2EC+SxUndvSzn6LRCwpfSvLrIfR5BKDQQZMaI6jPRC9dYvYFDRAuFEAnkwww8kBBNE/3VvzQ==} + engines: {node: '>=12'} + dependencies: + find-up: 5.0.0 + read-pkg: 6.0.0 + type-fest: 1.4.0 + /read-pkg@3.0.0: resolution: { @@ -24932,6 +25002,15 @@ packages: type-fest: 0.6.0 dev: true + /read-pkg@6.0.0: + resolution: {integrity: sha512-X1Fu3dPuk/8ZLsMhEj5f4wFAF0DWoK7qhGJvgaijocXxBmSToKfbFtqbxMO7bVjNA1dmE5huAzjXj/ey86iw9Q==} + engines: {node: '>=12'} + dependencies: + '@types/normalize-package-data': 2.4.1 + normalize-package-data: 3.0.3 + parse-json: 5.2.0 + type-fest: 1.4.0 + /read@2.1.0: resolution: { @@ -26067,6 +26146,22 @@ packages: } engines: { node: '>=12' } +<<<<<<< HEAD +======= + /slash@5.1.0: + resolution: {integrity: sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==} + engines: {node: '>=14.16'} + dev: true + + /slice-ansi@4.0.0: + resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==} + engines: {node: '>=10'} + dependencies: + ansi-styles: 4.3.0 + astral-regex: 2.0.0 + is-fullwidth-code-point: 3.0.0 + +>>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) /slice-ansi@5.0.0: resolution: { @@ -26614,7 +26709,6 @@ packages: engines: { node: '>=12' } dependencies: min-indent: 1.0.1 - dev: true /strip-json-comments@3.1.1: resolution: @@ -26803,6 +26897,13 @@ packages: has-flag: 4.0.0 dev: true + /supports-hyperlinks@3.0.0: + resolution: {integrity: sha512-QBDPHyPQDRTy9ku4URNGY5Lah8PAaXs6tAAwp55sL5WCsSW7GIfdf6W5ixfziW+t7wh3GVvHyHHyQ1ESsoRvaA==} + engines: {node: '>=14.18'} + dependencies: + has-flag: 4.0.0 + supports-color: 7.2.0 + /supports-preserve-symlinks-flag@1.0.0: resolution: { @@ -29250,7 +29351,6 @@ packages: dependencies: imurmurhash: 0.1.4 signal-exit: 4.1.0 - dev: true /write-json-file@3.2.0: resolution: From 9c5d844ae1cbd57c37cd81cb8cbefc3b38539251 Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Wed, 22 Nov 2023 15:00:44 -0300 Subject: [PATCH 3/9] chore: fix rebase errors --- pnpm-lock.yaml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 45636da1c3..22aa661b26 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3090,7 +3090,6 @@ packages: '@csstools/css-tokenizer': ^2.2.1 dependencies: '@csstools/css-tokenizer': 2.2.1 - dev: true /@csstools/css-tokenizer@2.2.1: resolution: @@ -3112,7 +3111,6 @@ packages: dependencies: '@csstools/css-parser-algorithms': 2.3.2(@csstools/css-tokenizer@2.2.1) '@csstools/css-tokenizer': 2.2.1 - dev: true /@csstools/postcss-cascade-layers@4.0.1(postcss@8.4.31): resolution: @@ -3517,7 +3515,6 @@ packages: postcss-selector-parser: ^6.0.13 dependencies: postcss-selector-parser: 6.0.13 - dev: true /@discoveryjs/json-ext@0.5.7: resolution: @@ -17462,6 +17459,9 @@ packages: merge2: 1.4.1 slash: 4.0.0 + /globjoin@0.1.4: + resolution: {integrity: sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg==} + /goober@2.1.13(csstype@3.1.2): resolution: { @@ -24027,6 +24027,17 @@ packages: postcss: 8.4.31 dev: true + /postcss-resolve-nested-selector@0.1.1: + resolution: {integrity: sha512-HvExULSwLqHLgUy1rl3ANIqCsvMS0WHss2UOsXhXnQaZ9VCc2oBvIpXrl00IUFT5ZDITME0o6oiXeiHr2SAIfw==} + + /postcss-safe-parser@6.0.0(postcss@8.4.31): + resolution: {integrity: sha512-FARHN8pwH+WiS2OPCxJI8FuRJpTVnn6ZNFiqAM2aeW2LwTHWWmWgIyKC6cUo0L8aeKiF/14MNvnpls6R2PBeMQ==} + engines: {node: '>=12.0'} + peerDependencies: + postcss: ^8.3.3 + dependencies: + postcss: 8.4.31 + /postcss-selector-not@7.0.1(postcss@8.4.31): resolution: { From df2076a8db1d5317862f0130740ceef47d031145 Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Wed, 22 Nov 2023 17:46:09 -0300 Subject: [PATCH 4/9] test: fix test error --- packages/stylelint/package.json | 3 ++- packages/stylelint/src/index.js | 4 ++-- .../plugins/{no-space-px-values => no-space-in-px}/index.js | 2 +- .../{no-space-px-values => no-space-in-px}/index.test.js | 4 ++++ pnpm-lock.yaml | 6 +++--- 5 files changed, 12 insertions(+), 7 deletions(-) rename packages/stylelint/src/plugins/{no-space-px-values => no-space-in-px}/index.js (97%) rename packages/stylelint/src/plugins/{no-space-px-values => no-space-in-px}/index.test.js (92%) diff --git a/packages/stylelint/package.json b/packages/stylelint/package.json index e2b783ecee..463435f2e6 100644 --- a/packages/stylelint/package.json +++ b/packages/stylelint/package.json @@ -39,7 +39,8 @@ "stylelint": "^14.15.0 || ^15.0.0" }, "devDependencies": { - "tsup": "7.2.0" + "tsup": "7.2.0", + "jest-preset-stylelint": "^6.3.2" }, "dependencies": {}, "jest": { diff --git a/packages/stylelint/src/index.js b/packages/stylelint/src/index.js index b2855d14c8..50915ec594 100644 --- a/packages/stylelint/src/index.js +++ b/packages/stylelint/src/index.js @@ -1,7 +1,7 @@ 'use strict' const textPlugin = require('./plugins/no-text-property') -const spacePlugin = require('./plugins/no-space-px-values') +const spacePlugin = require('./plugins/no-space-in-px') const colorRules = { 'color-no-invalid-hex': [ @@ -17,7 +17,7 @@ const typographyRules = { } const spaceRules = { - 'shoreline/no-space-px-values': true, + 'shoreline/no-space-in-px': true, } module.exports = { diff --git a/packages/stylelint/src/plugins/no-space-px-values/index.js b/packages/stylelint/src/plugins/no-space-in-px/index.js similarity index 97% rename from packages/stylelint/src/plugins/no-space-px-values/index.js rename to packages/stylelint/src/plugins/no-space-in-px/index.js index ce51089497..c7d3d6de1e 100644 --- a/packages/stylelint/src/plugins/no-space-px-values/index.js +++ b/packages/stylelint/src/plugins/no-space-in-px/index.js @@ -3,7 +3,7 @@ const { replaceDeclaration } = require('../../utils/replace-declaration.mjs') const { ruleMessages, validateOptions, report } = stylelint.utils -const ruleName = 'shoreline/no-space-px-values' +const ruleName = 'shoreline/no-space-in-px' const messages = ruleMessages(ruleName, { expected: (prop, value, expectedValue) => `Expected "${prop}: ${value}" to be "${prop}: ${expectedValue}".`, diff --git a/packages/stylelint/src/plugins/no-space-px-values/index.test.js b/packages/stylelint/src/plugins/no-space-in-px/index.test.js similarity index 92% rename from packages/stylelint/src/plugins/no-space-px-values/index.test.js rename to packages/stylelint/src/plugins/no-space-in-px/index.test.js index b3d3bfce9b..ca59459d6d 100644 --- a/packages/stylelint/src/plugins/no-space-px-values/index.test.js +++ b/packages/stylelint/src/plugins/no-space-in-px/index.test.js @@ -19,6 +19,10 @@ testRule({ code: 'padding-left: 1rem', description: 'Defining a padding-left', }, + { + code: 'top: 16px', + description: 'Defining a top value', + }, ], reject: [ { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 22aa661b26..c748e0c2ea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -120,9 +120,6 @@ importers: jest-environment-jsdom: specifier: 29.6.2 version: 29.6.2 - jest-preset-stylelint: - specifier: ^6.3.2 - version: 6.3.2(jest@29.6.2) jest-watch-typeahead: specifier: 2.2.2 version: 2.2.2(jest@29.6.2) @@ -450,6 +447,9 @@ importers: specifier: ^14.15.0 || ^15.0.0 version: 15.11.0 devDependencies: + jest-preset-stylelint: + specifier: ^6.3.2 + version: 6.3.2(jest@29.6.2) tsup: specifier: 7.2.0 version: 7.2.0(@swc/core@1.2.241)(postcss@8.4.31)(typescript@4.9.5) From c62738863d21c19e6e87198ddc5937bdbcf87516 Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Wed, 22 Nov 2023 18:50:20 -0300 Subject: [PATCH 5/9] test: fix test errors --- jest.config.js | 27 +++++++++++++++++++ package.json | 3 ++- .../src/plugins/no-space-in-px/index.js | 2 +- .../src/plugins/no-text-property/index.js | 2 +- ...declaration.mjs => replace-declaration.js} | 0 pnpm-lock.yaml | 3 +++ 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 jest.config.js rename packages/stylelint/src/utils/{replace-declaration.mjs => replace-declaration.js} (100%) diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000000..1daeb37d67 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,27 @@ +module.exports = { + verbose: true, + collectCoverageFrom: [ + 'packages/**/*.{ts,tsx}', + '!packages/**/*.stories.tsx', + '!packages/**/dist/**', + '!packages/**/.storybook/**', + ], + testMatch: ['**/?(*.)+(test).[jt]s?(x)', '!**/*.vitest.test*'], + testEnvironment: 'jsdom', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + transform: { + '^.+\\.(ts|tsx|js|jsx)?$': '@swc-node/jest', + }, + transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'], + setupFilesAfterEnv: ['./scripts/setup-test.ts'], + globals: { + 'ts-jest': { + tsconfig: 'tsconfig.json', + }, + }, + watchPlugins: [ + 'jest-watch-typeahead/filename', + 'jest-watch-typeahead/testname', + ], + preset: 'jest-preset-stylelint', +} diff --git a/package.json b/package.json index a157d2ea87..a265b598f6 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,8 @@ "tsup": "8.0.1", "stylelint": "^15.11.0", "stylelint-prettier": "^4.0.2", - "@vtex/shoreline-stylelint": "workspace" + "@vtex/shoreline-stylelint": "workspace", + "jest-preset-stylelint": "^6.3.2" }, "lint-staged": { "*.{ts,tsx,js,jsx}": [ diff --git a/packages/stylelint/src/plugins/no-space-in-px/index.js b/packages/stylelint/src/plugins/no-space-in-px/index.js index c7d3d6de1e..24dd8b710c 100644 --- a/packages/stylelint/src/plugins/no-space-in-px/index.js +++ b/packages/stylelint/src/plugins/no-space-in-px/index.js @@ -1,5 +1,5 @@ const stylelint = require('stylelint') -const { replaceDeclaration } = require('../../utils/replace-declaration.mjs') +const { replaceDeclaration } = require('../../utils/replace-declaration.js') const { ruleMessages, validateOptions, report } = stylelint.utils diff --git a/packages/stylelint/src/plugins/no-text-property/index.js b/packages/stylelint/src/plugins/no-text-property/index.js index 4d91890444..2c68d46fbc 100644 --- a/packages/stylelint/src/plugins/no-text-property/index.js +++ b/packages/stylelint/src/plugins/no-text-property/index.js @@ -1,5 +1,5 @@ const stylelint = require('stylelint') -const { replaceDeclaration } = require('../../utils/replace-declaration.mjs') +const { replaceDeclaration } = require('../../utils/replace-declaration.js') const { ruleMessages, validateOptions, report } = stylelint.utils diff --git a/packages/stylelint/src/utils/replace-declaration.mjs b/packages/stylelint/src/utils/replace-declaration.js similarity index 100% rename from packages/stylelint/src/utils/replace-declaration.mjs rename to packages/stylelint/src/utils/replace-declaration.js diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c748e0c2ea..7ad715bb1c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -120,6 +120,9 @@ importers: jest-environment-jsdom: specifier: 29.6.2 version: 29.6.2 + jest-preset-stylelint: + specifier: ^6.3.2 + version: 6.3.2(jest@29.6.2) jest-watch-typeahead: specifier: 2.2.2 version: 2.2.2(jest@29.6.2) From 9bf12a4d804021bb5025e50b519b1b68a33df41b Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Fri, 24 Nov 2023 12:08:06 -0300 Subject: [PATCH 6/9] docs(shoreline-stylelint): add package documentation --- .../components/src/text-input/text-input.css | 1 + packages/stylelint/README.md | 45 +++++++++++++++ packages/stylelint/src/index.js | 21 +------ .../src/plugins/no-px-values/README.md | 55 +++++++++++++++++++ .../{no-space-in-px => no-px-values}/index.js | 2 +- .../index.test.js | 0 .../src/plugins/no-text-property/README.md | 54 ++++++++++++++++++ .../src/plugins/no-text-property/index.js | 10 ++-- 8 files changed, 163 insertions(+), 25 deletions(-) create mode 100644 packages/stylelint/README.md create mode 100644 packages/stylelint/src/plugins/no-px-values/README.md rename packages/stylelint/src/plugins/{no-space-in-px => no-px-values}/index.js (97%) rename packages/stylelint/src/plugins/{no-space-in-px => no-px-values}/index.test.js (100%) create mode 100644 packages/stylelint/src/plugins/no-text-property/README.md diff --git a/packages/components/src/text-input/text-input.css b/packages/components/src/text-input/text-input.css index fea1bbe707..124061f18d 100644 --- a/packages/components/src/text-input/text-input.css +++ b/packages/components/src/text-input/text-input.css @@ -7,6 +7,7 @@ [data-sl-text-input-container] { height: 2.75rem; width: 100%; + text: var(--sl-text-body); font: var(--sl-text-body-font); letter-spacing: var(--sl-text-body-letter-spacing); border-radius: var(--sl-border-radius-medium); diff --git a/packages/stylelint/README.md b/packages/stylelint/README.md new file mode 100644 index 0000000000..acf6eb6c81 --- /dev/null +++ b/packages/stylelint/README.md @@ -0,0 +1,45 @@ +# Shoreline Stylelint + +A configuration of [Stylelint]() rules to help with the Shoreline adoption. + +## How to run? + +All files: + +```bash +pnpm stylelint **/*.css +``` + +Specific file: + +```bash +pnpm run stylelint src/example.css +``` + +Fix: + +```bash +pnpm stylelint **/*.css --fix +``` + +### Development + +### Add new rules + +1. Refer to the [Writing rules](https://stylelint.io/developer-guide/rules) guide of the Stylelint documentation + +### Build custom rules + +1. Refer to the [Writing plugins](https://stylelint.io/developer-guide/plugins) guide of the Stylelint documentation +2. Create your rule in the `/src/plugins` directory +3. Validate your plugin with tests (reference sibling plugins for examples) + +Useful references: + +1. [PostCSS API](https://postcss.org/api/): It is useful when writing a new plugin. +2. [jest-preset-stylelint](https://github.com/stylelint/jest-preset-stylelint#usage): Use this documentation when writing tests. +3. [stylelint-prettier](https://github.com/prettier/stylelint-prettier) + +### Setup new rule/plugin + +You must setup the new rule or plugin on [the Stylelint configuration file](./src/index.js) diff --git a/packages/stylelint/src/index.js b/packages/stylelint/src/index.js index 50915ec594..ea86ee6100 100644 --- a/packages/stylelint/src/index.js +++ b/packages/stylelint/src/index.js @@ -1,29 +1,12 @@ 'use strict' const textPlugin = require('./plugins/no-text-property') -const spacePlugin = require('./plugins/no-space-in-px') - -const colorRules = { - 'color-no-invalid-hex': [ - true, - { - message: 'Please use a Shoreline color token instead of %s', - }, - ], -} - -const typographyRules = { - 'shoreline/no-text-property': true, -} - -const spaceRules = { - 'shoreline/no-space-in-px': true, -} +const spacePlugin = require('./plugins/no-px-values') module.exports = { plugins: [textPlugin, spacePlugin], reportDescriptionlessDisables: true, reportNeedlessDisables: true, reportInvalidScopeDisables: true, - rules: { ...colorRules, ...typographyRules, ...spaceRules }, + rules: { 'shoreline/no-text-property': true, 'shoreline/no-px-values': true }, } diff --git a/packages/stylelint/src/plugins/no-px-values/README.md b/packages/stylelint/src/plugins/no-px-values/README.md new file mode 100644 index 0000000000..5bc1d99841 --- /dev/null +++ b/packages/stylelint/src/plugins/no-px-values/README.md @@ -0,0 +1,55 @@ +# shoreline/no-px-values + +Disallows use of `px` values. + +```diff + +// Do ++ padding: 1rem; ++ margin: 1rem 0.5rem; +// Don't +- padding: 16px; +- margin: 16px 8px; +``` + +## How to configure? + +```js +const stylelintConfig = { + rules: { + 'shoreline/no-px-values': true, + }, +} +``` + +## How to run? + +All files: + +```bash +pnpm stylelint **/*.css +``` + +Specific file: + +```bash +pnpm run stylelint src/example.css +``` + +## Fix + +```bash +pnpm stylelint **/*.css --fix +``` + +```diff +- margin: 16px 8px; ++ margin: 1rem 0.5rem; +``` + +## Output + +```bash + 10:5 ✖ Expected "padding: 16px" to be "padding: 1rem". shoreline/no-px-values + 11:5 ✖ Expected "margin: 8px 4px" to be "margin: 0.5rem 0.25rem". shoreline/no-px-values +``` diff --git a/packages/stylelint/src/plugins/no-space-in-px/index.js b/packages/stylelint/src/plugins/no-px-values/index.js similarity index 97% rename from packages/stylelint/src/plugins/no-space-in-px/index.js rename to packages/stylelint/src/plugins/no-px-values/index.js index 24dd8b710c..f5f91d0c64 100644 --- a/packages/stylelint/src/plugins/no-space-in-px/index.js +++ b/packages/stylelint/src/plugins/no-px-values/index.js @@ -3,7 +3,7 @@ const { replaceDeclaration } = require('../../utils/replace-declaration.js') const { ruleMessages, validateOptions, report } = stylelint.utils -const ruleName = 'shoreline/no-space-in-px' +const ruleName = 'shoreline/no-px-values' const messages = ruleMessages(ruleName, { expected: (prop, value, expectedValue) => `Expected "${prop}: ${value}" to be "${prop}: ${expectedValue}".`, diff --git a/packages/stylelint/src/plugins/no-space-in-px/index.test.js b/packages/stylelint/src/plugins/no-px-values/index.test.js similarity index 100% rename from packages/stylelint/src/plugins/no-space-in-px/index.test.js rename to packages/stylelint/src/plugins/no-px-values/index.test.js diff --git a/packages/stylelint/src/plugins/no-text-property/README.md b/packages/stylelint/src/plugins/no-text-property/README.md new file mode 100644 index 0000000000..5dc3ca4a92 --- /dev/null +++ b/packages/stylelint/src/plugins/no-text-property/README.md @@ -0,0 +1,54 @@ +# shoreline/no-text-property + +Disallows use of `px` values. + +```diff + +// Do ++ font: var(--sl-text-body-font); ++ letter-spacing: var(--sl-text-body-letter-spacing); +// Don't +- text: var(--sl-text-body); +``` + +## How to configure? + +```js +const stylelintConfig = { + rules: { + 'shoreline/no-text-property': true, + }, +} +``` + +## How to run? + +All files: + +```bash +pnpm stylelint **/*.css +``` + +Specific file: + +```bash +pnpm run stylelint src/example.css +``` + +## Fix + +```bash +pnpm stylelint **/*.css --fix +``` + +```diff +- text: var(--sl-text-body); ++ font: var(--sl-text-body-font); ++ letter-spacing: var(--sl-text-body-letter-spacing); +``` + +## Output + +```bash + 10:5 ✖ Expected "text" property to be splited in "font" and "letter-spacing" shoreline/no-text-property +``` diff --git a/packages/stylelint/src/plugins/no-text-property/index.js b/packages/stylelint/src/plugins/no-text-property/index.js index 2c68d46fbc..9aafd2053d 100644 --- a/packages/stylelint/src/plugins/no-text-property/index.js +++ b/packages/stylelint/src/plugins/no-text-property/index.js @@ -30,19 +30,19 @@ module.exports = stylelint.createPlugin( if (isAutoFixing) { const hasShorelinePrefix = decl.value.includes(textTokenPrefix) - const newFontValue = hasShorelinePrefix + const fontValue = hasShorelinePrefix ? decl.value.replace(')', '-font)') : decl.value - const newLetterSpacingValue = hasShorelinePrefix - ? newFontValue.replace('font', 'letter-spacing') + const letterSpacingValue = hasShorelinePrefix + ? fontValue.replace('font', 'letter-spacing') : decl.value - replaceDeclaration(decl, newFontValue, 'font') + replaceDeclaration(decl, fontValue, 'font') decl.cloneAfter({ prop: 'letter-spacing', - value: newLetterSpacingValue, + value: letterSpacingValue, }) } else { report({ From d0b90730d3caa4c4a0e71ef2b6698d07d62b6bea Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Fri, 24 Nov 2023 12:10:20 -0300 Subject: [PATCH 7/9] chore: revert text-input change --- packages/components/src/text-input/text-input.css | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/components/src/text-input/text-input.css b/packages/components/src/text-input/text-input.css index 124061f18d..fea1bbe707 100644 --- a/packages/components/src/text-input/text-input.css +++ b/packages/components/src/text-input/text-input.css @@ -7,7 +7,6 @@ [data-sl-text-input-container] { height: 2.75rem; width: 100%; - text: var(--sl-text-body); font: var(--sl-text-body-font); letter-spacing: var(--sl-text-body-letter-spacing); border-radius: var(--sl-border-radius-medium); From 069ee06ff495439f02e2c1398d8dfb24c17f5eaa Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Mon, 27 Nov 2023 18:55:30 -0300 Subject: [PATCH 8/9] test: change from jest to vitest --- jest.config.js | 1 - package.json | 3 +- packages/stylelint/package.json | 11 +- packages/stylelint/src/index.types.d.ts | 2 - .../src/plugins/no-px-values/index.test.js | 47 ---- .../plugins/no-px-values/index.vitest.test.js | 66 +++++ .../plugins/no-text-property/index.test.js | 39 --- .../no-text-property/index.vitest.test.js | 63 +++++ pnpm-lock.yaml | 251 ++++++++++++------ 9 files changed, 308 insertions(+), 175 deletions(-) delete mode 100644 packages/stylelint/src/index.types.d.ts delete mode 100644 packages/stylelint/src/plugins/no-px-values/index.test.js create mode 100644 packages/stylelint/src/plugins/no-px-values/index.vitest.test.js delete mode 100644 packages/stylelint/src/plugins/no-text-property/index.test.js create mode 100644 packages/stylelint/src/plugins/no-text-property/index.vitest.test.js diff --git a/jest.config.js b/jest.config.js index 1daeb37d67..015d0d4343 100644 --- a/jest.config.js +++ b/jest.config.js @@ -23,5 +23,4 @@ module.exports = { 'jest-watch-typeahead/filename', 'jest-watch-typeahead/testname', ], - preset: 'jest-preset-stylelint', } diff --git a/package.json b/package.json index a265b598f6..a157d2ea87 100644 --- a/package.json +++ b/package.json @@ -93,8 +93,7 @@ "tsup": "8.0.1", "stylelint": "^15.11.0", "stylelint-prettier": "^4.0.2", - "@vtex/shoreline-stylelint": "workspace", - "jest-preset-stylelint": "^6.3.2" + "@vtex/shoreline-stylelint": "workspace" }, "lint-staged": { "*.{ts,tsx,js,jsx}": [ diff --git a/packages/stylelint/package.json b/packages/stylelint/package.json index 463435f2e6..1e88e816dd 100644 --- a/packages/stylelint/package.json +++ b/packages/stylelint/package.json @@ -24,8 +24,7 @@ "scripts": { "prebuild": "rm -rf dist", "dev": "tsup --watch", - "build": "npm run prebuild && tsup", - "test": "jest" + "build": "npm run prebuild && tsup" }, "repository": { "directory": "packages/stylelint", @@ -39,11 +38,7 @@ "stylelint": "^14.15.0 || ^15.0.0" }, "devDependencies": { - "tsup": "7.2.0", - "jest-preset-stylelint": "^6.3.2" + "tsup": "7.2.0" }, - "dependencies": {}, - "jest": { - "preset": "jest-preset-stylelint" - } + "dependencies": {} } diff --git a/packages/stylelint/src/index.types.d.ts b/packages/stylelint/src/index.types.d.ts deleted file mode 100644 index de5aae157d..0000000000 --- a/packages/stylelint/src/index.types.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -declare let testRule: import('jest-preset-stylelint').TestRule diff --git a/packages/stylelint/src/plugins/no-px-values/index.test.js b/packages/stylelint/src/plugins/no-px-values/index.test.js deleted file mode 100644 index ca59459d6d..0000000000 --- a/packages/stylelint/src/plugins/no-px-values/index.test.js +++ /dev/null @@ -1,47 +0,0 @@ -const { ruleName, messages } = require('.') - -// eslint-disable-next-line no-undef -testRule({ - fix: true, - ruleName, - plugins: [__dirname], - config: {}, - accept: [ - { - code: 'margin: 1rem', - description: 'Defining a margin', - }, - { - code: 'padding: 1rem 0.5rem', - description: 'Defining a padding', - }, - { - code: 'padding-left: 1rem', - description: 'Defining a padding-left', - }, - { - code: 'top: 16px', - description: 'Defining a top value', - }, - ], - reject: [ - { - code: 'margin: 16px', - fixed: 'margin: 1rem', - description: 'Defining a margin', - message: messages.expected('margin', '16px', '1rem'), - }, - { - code: 'padding: 16px 8px', - description: 'Defining a padding', - fixed: 'padding: 1rem 0.5rem', - message: messages.expected('padding', '16px 8px', '1rem 0.5rem'), - }, - { - code: 'padding-left: 22px', - description: 'Defining a padding-left', - fixed: 'padding-left: 1.375rem', - message: messages.expected('padding-left', '22px', '1.375rem'), - }, - ], -}) diff --git a/packages/stylelint/src/plugins/no-px-values/index.vitest.test.js b/packages/stylelint/src/plugins/no-px-values/index.vitest.test.js new file mode 100644 index 0000000000..22416a497c --- /dev/null +++ b/packages/stylelint/src/plugins/no-px-values/index.vitest.test.js @@ -0,0 +1,66 @@ +import { test, expect } from 'vitest' + +const plugin = require('.') + +const { ruleName, messages } = plugin + +const stylelint = require('stylelint') + +test('it allows the use of valid space values on space properties', async () => { + const code = ` + margin: 1rem; + padding: 1rem 0.5rem; + padding-left: 1rem; + top: 16px; + ` + + const result = await stylelint.lint({ + code, + config: { plugins: [plugin], rules: { [ruleName]: true } }, + }) + + expect(result.results[0].warnings).toHaveLength(0) +}) + +test('it disallows the use of px values on space properties', async () => { + const code = ` + margin: 16px; + ` + + const result = await stylelint.lint({ + code, + config: { + plugins: [plugin], + rules: { [ruleName]: true }, + }, + }) + + expect(result.results[0].warnings).toHaveLength(1) + + const warning = result.results[0].warnings[0] + + expect(warning.rule).toBe(ruleName) + expect(warning.severity).toBe('error') + expect(warning.text).toBe(messages.expected('margin', '16px', '1rem')) +}) + +test('it fix the error of invalid space property value to a valid one', async () => { + const code = ` + padding: 22px 8px; + ` + + const result = await stylelint.lint({ + code, + config: { + fix: true, + plugins: [plugin], + rules: { [ruleName]: true }, + }, + }) + + expect(result.results[0].warnings).toHaveLength(0) + + expect(result.output).toBe(` + padding: 1.375rem 0.5rem; + `) +}) diff --git a/packages/stylelint/src/plugins/no-text-property/index.test.js b/packages/stylelint/src/plugins/no-text-property/index.test.js deleted file mode 100644 index 73db2cfcc0..0000000000 --- a/packages/stylelint/src/plugins/no-text-property/index.test.js +++ /dev/null @@ -1,39 +0,0 @@ -const { ruleName, messages } = require('.') - -// eslint-disable-next-line no-undef -testRule({ - fix: true, - ruleName, - plugins: [__dirname], - config: {}, - accept: [ - { - code: 'font: var(--sl-text-body-font)', - description: 'Defining a font', - }, - { - code: 'letter-spacing: var(--sl-text-body-letter-spacing)', - description: 'Defining a letter-spacing', - }, - ], - reject: [ - { - code: `text: var(--sl-text-body)`, - fixed: `font: var(--sl-text-body-font);letter-spacing: var(--sl-text-body-letter-spacing)`, - description: 'Defining a text rule', - message: messages.expected, - }, - { - code: `text: test`, - fixed: `font: test;letter-spacing: test`, - description: 'Defining a disallowed include name with a namespace', - message: messages.expected, - }, - { - code: `text: var(--sl-my-custom-text-token)`, - fixed: `font: var(--sl-my-custom-text-token);letter-spacing: var(--sl-my-custom-text-token)`, - description: 'Defining a disallowed include name with a namespace', - message: messages.expected, - }, - ], -}) diff --git a/packages/stylelint/src/plugins/no-text-property/index.vitest.test.js b/packages/stylelint/src/plugins/no-text-property/index.vitest.test.js new file mode 100644 index 0000000000..f9cc3b7d92 --- /dev/null +++ b/packages/stylelint/src/plugins/no-text-property/index.vitest.test.js @@ -0,0 +1,63 @@ +import { test, expect } from 'vitest' + +const plugin = require('.') + +const { ruleName, messages } = plugin + +const stylelint = require('stylelint') + +test('it allows the use of valid typography properties and values', async () => { + const code = ` + font: var(--sl-text-body-font); + ` + + const result = await stylelint.lint({ + code, + config: { plugins: [plugin], rules: { [ruleName]: true } }, + }) + + expect(result.results[0].warnings).toHaveLength(0) +}) + +test('it disallows the use of invalid typography properties', async () => { + const code = ` + text: var(--sl-text-body); + ` + + const result = await stylelint.lint({ + code, + config: { plugins: [plugin], rules: { [ruleName]: true } }, + }) + + expect(result.results[0].warnings).toHaveLength(1) + + const warning = result.results[0].warnings[0] + + expect(warning.rule).toBe(ruleName) + expect(warning.severity).toBe('error') + expect(warning.text).toBe(messages.expected) +}) + +test('it fix the error of invalid typography property usage to a valid one', async () => { + const code = ` + text: var(--sl-text-body); + ` + + const result = await stylelint.lint({ + code, + config: { + fix: true, + plugins: [plugin], + rules: { [ruleName]: true }, + }, + }) + + expect(result.results[0].warnings).toHaveLength(0) + + expect(result.results[0].warnings).toHaveLength(0) + + expect(result.output).toBe(` + font: var(--sl-text-body-font); + letter-spacing: var(--sl-text-body-letter-spacing); + `) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ad715bb1c..f08374d5f6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -67,15 +67,9 @@ importers: '@vtex/prettier-config': specifier: ^0.3.1 version: 0.3.6(prettier@2.8.8) -<<<<<<< HEAD '@vtex/shoreline-test-utils': specifier: workspace:* version: link:packages/test-utils -======= - '@vtex/shoreline-stylelint': - specifier: workspace - version: link:packages/stylelint ->>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) '@vtex/tsconfig': specifier: ^0.5.6 version: 0.5.6(typescript@4.9.5) @@ -109,24 +103,6 @@ importers: husky: specifier: ^8.0.3 version: 8.0.3 -<<<<<<< HEAD -======= - jest: - specifier: 29.6.2 - version: 29.6.2(@types/node@20.4.5)(babel-plugin-macros@3.1.0) - jest-axe: - specifier: 8.0.0 - version: 8.0.0 - jest-environment-jsdom: - specifier: 29.6.2 - version: 29.6.2 - jest-preset-stylelint: - specifier: ^6.3.2 - version: 6.3.2(jest@29.6.2) - jest-watch-typeahead: - specifier: 2.2.2 - version: 2.2.2(jest@29.6.2) ->>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) jsdom: specifier: 23.0.0 version: 23.0.0 @@ -427,7 +403,6 @@ importers: specifier: ^0.5.0 version: link:../utils -<<<<<<< HEAD packages/test-utils: dependencies: '@testing-library/dom': @@ -443,20 +418,6 @@ importers: vitest: specifier: 0.34.6 version: 0.34.6(jsdom@23.0.0) -======= - packages/stylelint: - dependencies: - stylelint: - specifier: ^14.15.0 || ^15.0.0 - version: 15.11.0 - devDependencies: - jest-preset-stylelint: - specifier: ^6.3.2 - version: 6.3.2(jest@29.6.2) - tsup: - specifier: 7.2.0 - version: 7.2.0(@swc/core@1.2.241)(postcss@8.4.31)(typescript@4.9.5) ->>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) packages/theme: dependencies: @@ -11324,7 +11285,6 @@ packages: json-schema-traverse: 1.0.0 require-from-string: 2.0.2 uri-js: 4.4.1 - dev: true /anser@2.1.1: resolution: @@ -12035,6 +11995,9 @@ packages: integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==, } + /balanced-match@2.0.0: + resolution: {integrity: sha512-1ugUSr8BHXRnK23KfuYS+gVMC3LB8QGH9W1iGtDPsNWoQbgtXSExkBu2aDR4epiGWZOjZsj6lDl/N/AqqTC3UA==} + /base64-js@1.5.1: resolution: { @@ -12429,6 +12392,15 @@ packages: quick-lru: 4.0.1 dev: true + /camelcase-keys@7.0.2: + resolution: {integrity: sha512-Rjs1H+A9R+Ig+4E/9oyB66UC5Mj9Xq3N//vcLf2WzgdTi/3gUu3Z9KoqmlrEG4VuuLK8wJHofxzdQXz/knhiYg==} + engines: {node: '>=12'} + dependencies: + camelcase: 6.3.0 + map-obj: 4.3.0 + quick-lru: 5.1.1 + type-fest: 1.4.0 + /camelcase@5.3.1: resolution: { @@ -12954,6 +12926,9 @@ packages: hasBin: true dev: true + /colord@2.9.3: + resolution: {integrity: sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==} + /colorette@2.0.20: resolution: { @@ -13640,6 +13615,10 @@ packages: postcss-selector-parser: 6.0.13 dev: true + /css-functions-list@3.2.1: + resolution: {integrity: sha512-Nj5YcaGgBtuUmn1D7oHqPW0c9iui7xsTsj5lIX8ZgevdfhmjFfKB3r8moHJtNJnctnYXJyYX5I1pp90HM4TPgQ==} + engines: {node: '>=12 || >=16'} + /css-has-pseudo@6.0.0(postcss@8.4.31): resolution: { @@ -13700,6 +13679,13 @@ packages: nth-check: 2.1.1 dev: true + /css-tree@2.3.1: + resolution: {integrity: sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==} + engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0} + dependencies: + mdn-data: 2.0.30 + source-map-js: 1.0.2 + /css-what@6.1.0: resolution: { @@ -14273,7 +14259,6 @@ packages: dependencies: decamelize: 1.2.0 map-obj: 1.0.1 - dev: true /decamelize@1.2.0: resolution: @@ -16454,6 +16439,12 @@ packages: flat-cache: 3.2.0 dev: true + /file-entry-cache@7.0.2: + resolution: {integrity: sha512-TfW7/1iI4Cy7Y8L6iqNdZQVvdXn0f8B4QcIXmkIbtTIe/Okm/nSlHb4IwGzRVOd3WfSieCgvf5cMzEfySAIl0g==} + engines: {node: '>=12.0.0'} + dependencies: + flat-cache: 3.2.0 + /file-system-cache@2.3.0: resolution: { @@ -16593,7 +16584,6 @@ packages: dependencies: locate-path: 6.0.0 path-exists: 4.0.0 - dev: true /find-up@6.3.0: resolution: @@ -16661,7 +16651,6 @@ packages: flatted: 3.2.9 keyv: 4.5.4 rimraf: 3.0.2 - dev: true /flat@5.0.2: resolution: @@ -17380,6 +17369,12 @@ packages: is-windows: 1.0.2 resolve-dir: 1.0.1 + /global-modules@2.0.0: + resolution: {integrity: sha512-NGbfmJBp9x8IxyJSd1P+otYK8vonoJactOogrVfFRIAEY1ukil8RSKDz2Yo7wh1oihl51l/r6W4epkeKJHqL8A==} + engines: {node: '>=6'} + dependencies: + global-prefix: 3.0.0 + /global-prefix@1.0.2: resolution: { @@ -17393,6 +17388,14 @@ packages: is-windows: 1.0.2 which: 1.3.1 + /global-prefix@3.0.0: + resolution: {integrity: sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==} + engines: {node: '>=6'} + dependencies: + ini: 1.3.8 + kind-of: 6.0.3 + which: 1.3.1 + /globals@11.12.0: resolution: { @@ -17971,6 +17974,10 @@ packages: engines: { node: '>=8' } dev: true + /html-tags@3.3.1: + resolution: {integrity: sha512-ztqyC3kLto0e9WbNp0aeP+M3kTt+nbaIveGmUxAtZa+8iFgKLUOD4YKM5j+f3QD89bra7UeumolZHKuOXnTmeQ==} + engines: {node: '>=8'} + /html-webpack-plugin@5.5.0(webpack@5.88.0): resolution: { @@ -18203,6 +18210,10 @@ packages: resolve-from: 5.0.0 dev: true + /import-lazy@4.0.0: + resolution: {integrity: sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==} + engines: {node: '>=8'} + /import-local@3.1.0: resolution: { @@ -18238,6 +18249,10 @@ packages: } engines: { node: '>=8' } + /indent-string@5.0.0: + resolution: {integrity: sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==} + engines: {node: '>=12'} + /inflight@1.0.6: resolution: { @@ -19220,15 +19235,6 @@ packages: fsevents: 2.3.3 dev: true - /jest-preset-stylelint@6.3.2(jest@29.6.2): - resolution: {integrity: sha512-OnodJG8lMAzvhx5WjcGdne6TnGSWASlcUySd3sY+4E3Adgv4LcxBaNT6E15u5WTPpDsElaJqYNveANf2htR/Ng==} - engines: {node: ^14.15.0 || >=16.10.0} - peerDependencies: - jest: ^29.0.2 - dependencies: - jest: 29.6.2(@types/node@20.4.5)(babel-plugin-macros@3.1.0) - dev: true - /jest-regex-util@29.4.3: resolution: { @@ -19581,7 +19587,6 @@ packages: } dependencies: json-buffer: 3.0.1 - dev: true /khroma@2.0.0: resolution: @@ -20113,7 +20118,6 @@ packages: engines: { node: '>=10' } dependencies: p-locate: 5.0.0 - dev: true /locate-path@7.2.0: resolution: @@ -20180,6 +20184,9 @@ packages: } dev: true + /lodash.truncate@4.4.2: + resolution: {integrity: sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==} + /lodash.without@4.4.0: resolution: { @@ -20329,7 +20336,6 @@ packages: engines: { node: '>=10' } dependencies: yallist: 4.0.0 - dev: true /lru-cache@7.18.3: resolution: @@ -20514,6 +20520,9 @@ packages: '@babel/runtime': 7.22.5 remove-accents: 0.4.2 + /mathml-tag-names@2.1.3: + resolution: {integrity: sha512-APMBEanjybaPzUrfqU0IMU5I0AswKMH7k8OTLs0vvV4KZpExkTkY87nR/zpbuTPj+gARop7aGUbl11pnDfW6xg==} + /mdast-util-definitions@4.0.0: resolution: { @@ -20778,6 +20787,9 @@ packages: '@types/mdast': 3.0.10 dev: false + /mdn-data@2.0.30: + resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==} + /media-query-parser@2.0.2: resolution: { @@ -20829,6 +20841,23 @@ packages: engines: { node: '>= 0.10.0' } dev: true + /meow@10.1.5: + resolution: {integrity: sha512-/d+PQ4GKmGvM9Bee/DPa8z3mXs/pkvJE2KEThngVNOqtmljC6K7NMPxtc2JeZYTmpWb9k/TmxjeL18ez3h7vCw==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + '@types/minimist': 1.2.2 + camelcase-keys: 7.0.2 + decamelize: 5.0.1 + decamelize-keys: 1.1.0 + hard-rejection: 2.1.0 + minimist-options: 4.1.0 + normalize-package-data: 3.0.3 + read-pkg-up: 8.0.0 + redent: 4.0.0 + trim-newlines: 4.1.1 + type-fest: 1.4.0 + yargs-parser: 20.2.9 + /meow@8.1.2: resolution: { @@ -22942,7 +22971,6 @@ packages: engines: { node: '>=10' } dependencies: p-limit: 3.1.0 - dev: true /p-locate@6.0.0: resolution: @@ -24457,6 +24485,10 @@ packages: engines: { node: '>=8' } dev: true + /quick-lru@5.1.1: + resolution: {integrity: sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==} + engines: {node: '>=10'} + /raf@3.4.1: resolution: { @@ -25195,6 +25227,13 @@ packages: indent-string: 4.0.0 strip-indent: 3.0.0 + /redent@4.0.0: + resolution: {integrity: sha512-tYkDkVVtYkSVhuQ4zBgfvciymHaeuel+zFKXShfDnFP5SyVEP7qo70Rf1jTOTCx3vGNAbnEi/xFkcfQVMIBWag==} + engines: {node: '>=12'} + dependencies: + indent-string: 5.0.0 + strip-indent: 4.0.0 + /refractor@3.6.0: resolution: { @@ -25928,7 +25967,6 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 - dev: true /semver@7.5.4: resolution: @@ -26160,22 +26198,6 @@ packages: } engines: { node: '>=12' } -<<<<<<< HEAD -======= - /slash@5.1.0: - resolution: {integrity: sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==} - engines: {node: '>=14.16'} - dev: true - - /slice-ansi@4.0.0: - resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==} - engines: {node: '>=10'} - dependencies: - ansi-styles: 4.3.0 - astral-regex: 2.0.0 - is-fullwidth-code-point: 3.0.0 - ->>>>>>> 0b99ad60d (feat(stylelint): add @vtex/shoreline-stylelint configuration) /slice-ansi@5.0.0: resolution: { @@ -26319,7 +26341,6 @@ packages: dependencies: spdx-expression-parse: 3.0.1 spdx-license-ids: 3.0.11 - dev: true /spdx-exceptions@2.3.0: resolution: @@ -26336,7 +26357,6 @@ packages: dependencies: spdx-exceptions: 2.3.0 spdx-license-ids: 3.0.11 - dev: true /spdx-license-ids@3.0.11: resolution: @@ -26772,6 +26792,9 @@ packages: } dev: false + /style-search@0.1.0: + resolution: {integrity: sha512-Dj1Okke1C3uKKwQcetra4jSuk0DqbzbYtXipzFlFMZtowbF1x7BKJwB9AayVMyFARvU8EDrZdcax4At/452cAg==} + /style-to-object@0.4.1: resolution: { @@ -26822,6 +26845,66 @@ packages: react: 18.2.0 dev: false + /stylelint-prettier@4.0.2(prettier@2.8.8)(stylelint@15.11.0): + resolution: {integrity: sha512-EoHnR2PiaWgpGtoI4VW7AzneMfwmwQsNwQ+3/E2k/a+ju5yO6rfPfop4vzPQKcJN4ZM1YbspEOPu88D8538sbg==} + engines: {node: ^14.17.0 || >=16.0.0} + peerDependencies: + prettier: '>=3.0.0' + stylelint: '>=15.8.0' + dependencies: + prettier: 2.8.8 + prettier-linter-helpers: 1.0.0 + stylelint: 15.11.0 + dev: true + + /stylelint@15.11.0: + resolution: {integrity: sha512-78O4c6IswZ9TzpcIiQJIN49K3qNoXTM8zEJzhaTE/xRTCZswaovSEVIa/uwbOltZrk16X4jAxjaOhzz/hTm1Kw==} + engines: {node: ^14.13.1 || >=16.0.0} + hasBin: true + dependencies: + '@csstools/css-parser-algorithms': 2.3.2(@csstools/css-tokenizer@2.2.1) + '@csstools/css-tokenizer': 2.2.1 + '@csstools/media-query-list-parser': 2.1.5(@csstools/css-parser-algorithms@2.3.2)(@csstools/css-tokenizer@2.2.1) + '@csstools/selector-specificity': 3.0.0(postcss-selector-parser@6.0.13) + balanced-match: 2.0.0 + colord: 2.9.3 + cosmiconfig: 8.2.0 + css-functions-list: 3.2.1 + css-tree: 2.3.1 + debug: 4.3.4 + fast-glob: 3.3.1 + fastest-levenshtein: 1.0.16 + file-entry-cache: 7.0.2 + global-modules: 2.0.0 + globby: 11.1.0 + globjoin: 0.1.4 + html-tags: 3.3.1 + ignore: 5.2.4 + import-lazy: 4.0.0 + imurmurhash: 0.1.4 + is-plain-object: 5.0.0 + known-css-properties: 0.29.0 + mathml-tag-names: 2.1.3 + meow: 10.1.5 + micromatch: 4.0.5 + normalize-path: 3.0.0 + picocolors: 1.0.0 + postcss: 8.4.31 + postcss-resolve-nested-selector: 0.1.1 + postcss-safe-parser: 6.0.0(postcss@8.4.31) + postcss-selector-parser: 6.0.13 + postcss-value-parser: 4.2.0 + resolve-from: 5.0.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + style-search: 0.1.0 + supports-hyperlinks: 3.0.0 + svg-tags: 1.0.0 + table: 6.8.1 + write-file-atomic: 5.0.1 + transitivePeerDependencies: + - supports-color + /stylis@4.3.0: resolution: { @@ -26925,6 +27008,9 @@ packages: } engines: { node: '>= 0.4' } + /svg-tags@1.0.0: + resolution: {integrity: sha512-ovssysQTa+luh7A5Weu3Rta6FJlFBBbInjOh722LIt6klpU2/HtdUbszju/G4devcvk8PGt7FCLv5wftu3THUA==} + /swc-loader@0.2.3(@swc/core@1.3.96)(webpack@5.88.0): resolution: { @@ -26983,6 +27069,16 @@ packages: tslib: 2.6.2 dev: true + /table@6.8.1: + resolution: {integrity: sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==} + engines: {node: '>=10.0.0'} + dependencies: + ajv: 8.11.0 + lodash.truncate: 4.4.2 + slice-ansi: 4.0.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + /tapable@2.2.1: resolution: { @@ -27403,6 +27499,10 @@ packages: engines: { node: '>=8' } dev: true + /trim-newlines@4.1.1: + resolution: {integrity: sha512-jRKj0n0jXWo6kh62nA5TEh3+4igKDXLvzBJcPpiizP7oOolUrYIxmVBG9TOtHYFHoddUk6YvAkGeGoSVTXfQXQ==} + engines: {node: '>=12'} + /trough@2.1.0: resolution: { @@ -28606,7 +28706,6 @@ packages: dependencies: spdx-correct: 3.1.1 spdx-expression-parse: 3.0.1 - dev: true /validate-npm-package-name@3.0.0: resolution: From e2fb857e79bf6495471d23f71766cb19dabfde81 Mon Sep 17 00:00:00 2001 From: Lucas Arcoverde Date: Wed, 29 Nov 2023 15:41:05 -0300 Subject: [PATCH 9/9] feat: accept pr suggestions --- jest.config.js | 26 --------- packages/stylelint/package.json | 12 ++-- .../{index.vitest.test.js => index.test.js} | 2 +- .../{index.vitest.test.js => index.test.js} | 2 +- packages/stylelint/tsup.config.ts | 1 - pnpm-lock.yaml | 56 ++++++++++++------- 6 files changed, 42 insertions(+), 57 deletions(-) delete mode 100644 jest.config.js rename packages/stylelint/src/plugins/no-px-values/{index.vitest.test.js => index.test.js} (96%) rename packages/stylelint/src/plugins/no-text-property/{index.vitest.test.js => index.test.js} (96%) diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 015d0d4343..0000000000 --- a/jest.config.js +++ /dev/null @@ -1,26 +0,0 @@ -module.exports = { - verbose: true, - collectCoverageFrom: [ - 'packages/**/*.{ts,tsx}', - '!packages/**/*.stories.tsx', - '!packages/**/dist/**', - '!packages/**/.storybook/**', - ], - testMatch: ['**/?(*.)+(test).[jt]s?(x)', '!**/*.vitest.test*'], - testEnvironment: 'jsdom', - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - transform: { - '^.+\\.(ts|tsx|js|jsx)?$': '@swc-node/jest', - }, - transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'], - setupFilesAfterEnv: ['./scripts/setup-test.ts'], - globals: { - 'ts-jest': { - tsconfig: 'tsconfig.json', - }, - }, - watchPlugins: [ - 'jest-watch-typeahead/filename', - 'jest-watch-typeahead/testname', - ], -} diff --git a/packages/stylelint/package.json b/packages/stylelint/package.json index 1e88e816dd..ae9f0758e5 100644 --- a/packages/stylelint/package.json +++ b/packages/stylelint/package.json @@ -2,7 +2,7 @@ "name": "@vtex/shoreline-stylelint", "version": "0.0.0", "main": "./dist/index.js", - "module": "./dist/esm/index.js", + "module": "./dist/index.mjs", "types": "./dist/index.d.ts", "publishConfig": { "access": "public", @@ -14,12 +14,12 @@ "exports": { ".": { "require": "./dist/index.js", - "import": "./dist/esm/index.js", + "import": "./dist/index.mjs", "types": "./dist/index.d.ts" } }, "engines": { - "node": ">=16" + "node": ">=18" }, "scripts": { "prebuild": "rm -rf dist", @@ -36,9 +36,5 @@ }, "peerDependencies": { "stylelint": "^14.15.0 || ^15.0.0" - }, - "devDependencies": { - "tsup": "7.2.0" - }, - "dependencies": {} + } } diff --git a/packages/stylelint/src/plugins/no-px-values/index.vitest.test.js b/packages/stylelint/src/plugins/no-px-values/index.test.js similarity index 96% rename from packages/stylelint/src/plugins/no-px-values/index.vitest.test.js rename to packages/stylelint/src/plugins/no-px-values/index.test.js index 22416a497c..be7d76a38d 100644 --- a/packages/stylelint/src/plugins/no-px-values/index.vitest.test.js +++ b/packages/stylelint/src/plugins/no-px-values/index.test.js @@ -1,4 +1,4 @@ -import { test, expect } from 'vitest' +import { test, expect } from '@vtex/shoreline-test-utils' const plugin = require('.') diff --git a/packages/stylelint/src/plugins/no-text-property/index.vitest.test.js b/packages/stylelint/src/plugins/no-text-property/index.test.js similarity index 96% rename from packages/stylelint/src/plugins/no-text-property/index.vitest.test.js rename to packages/stylelint/src/plugins/no-text-property/index.test.js index f9cc3b7d92..0a803d0cbb 100644 --- a/packages/stylelint/src/plugins/no-text-property/index.vitest.test.js +++ b/packages/stylelint/src/plugins/no-text-property/index.test.js @@ -1,4 +1,4 @@ -import { test, expect } from 'vitest' +import { test, expect } from '@vtex/shoreline-test-utils' const plugin = require('.') diff --git a/packages/stylelint/tsup.config.ts b/packages/stylelint/tsup.config.ts index 98d57d9974..86855985ba 100644 --- a/packages/stylelint/tsup.config.ts +++ b/packages/stylelint/tsup.config.ts @@ -7,5 +7,4 @@ export default defineConfig({ sourcemap: true, clean: true, dts: true, - legacyOutput: true, }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f08374d5f6..0c627a2fb4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -67,6 +67,9 @@ importers: '@vtex/prettier-config': specifier: ^0.3.1 version: 0.3.6(prettier@2.8.8) + '@vtex/shoreline-stylelint': + specifier: workspace + version: link:packages/stylelint '@vtex/shoreline-test-utils': specifier: workspace:* version: link:packages/test-utils @@ -403,6 +406,12 @@ importers: specifier: ^0.5.0 version: link:../utils + packages/stylelint: + dependencies: + stylelint: + specifier: ^14.15.0 || ^15.0.0 + version: 15.11.0 + packages/test-utils: dependencies: '@testing-library/dom': @@ -584,8 +593,9 @@ packages: } engines: { node: '>=6.9.0' } dependencies: - '@babel/highlight': 7.22.20 + '@babel/highlight': 7.23.4 chalk: 2.4.2 + dev: false /@babel/code-frame@7.23.5: resolution: @@ -2426,7 +2436,7 @@ packages: } engines: { node: '>=6.9.0' } dependencies: - '@babel/code-frame': 7.22.13 + '@babel/code-frame': 7.23.5 '@babel/generator': 7.23.0 '@babel/helper-environment-visitor': 7.22.20 '@babel/helper-function-name': 7.23.0 @@ -2468,7 +2478,7 @@ packages: engines: { node: '>=6.9.0' } dependencies: '@babel/helper-string-parser': 7.22.5 - '@babel/helper-validator-identifier': 7.22.5 + '@babel/helper-validator-identifier': 7.22.20 to-fast-properties: 2.0.0 dev: true @@ -5285,7 +5295,7 @@ packages: p-reduce: 2.1.0 pacote: 15.2.0 pify: 5.0.0 - semver: 7.5.3 + semver: 7.5.4 slash: 3.0.0 validate-npm-package-license: 3.0.4 validate-npm-package-name: 5.0.0 @@ -12409,6 +12419,10 @@ packages: engines: { node: '>=6' } dev: true + /camelcase@6.3.0: + resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} + engines: {node: '>=10'} + /caniuse-lite@1.0.30001518: resolution: { @@ -14935,7 +14949,6 @@ packages: } dependencies: is-arrayish: 0.2.1 - dev: true /error-stack-parser@2.1.4: resolution: @@ -15657,7 +15670,7 @@ packages: peerDependencies: eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8 dependencies: - '@babel/runtime': 7.22.5 + '@babel/runtime': 7.22.6 aria-query: 5.3.0 array-includes: 3.1.6 array.prototype.flatmap: 1.3.1 @@ -16758,7 +16771,7 @@ packages: typescript: '>3.6.0' webpack: ^5.11.0 dependencies: - '@babel/code-frame': 7.22.13 + '@babel/code-frame': 7.23.5 chalk: 4.1.2 chokidar: 3.5.3 cosmiconfig: 7.0.1 @@ -18198,7 +18211,6 @@ packages: dependencies: parent-module: 1.0.1 resolve-from: 4.0.0 - dev: true /import-from@3.0.0: resolution: @@ -18285,7 +18297,7 @@ packages: promzard: 1.0.0 read: 2.1.0 read-package-json: 6.0.4 - semver: 7.5.3 + semver: 7.5.4 validate-npm-package-license: 3.0.4 validate-npm-package-name: 5.0.0 dev: true @@ -19799,7 +19811,7 @@ packages: npm-package-arg: 10.1.0 npm-registry-fetch: 14.0.5 proc-log: 3.0.0 - semver: 7.5.3 + semver: 7.5.4 sigstore: 1.8.0 ssri: 10.0.4 transitivePeerDependencies: @@ -20796,7 +20808,7 @@ packages: integrity: sha512-1N4qp+jE0pL5Xv4uEcwVUhIkwdUO3S/9gML90nqKA7v7FcOS5vUtatfzok9S9U1EJU8dHWlcv95WLnKmmxZI9w==, } dependencies: - '@babel/runtime': 7.22.5 + '@babel/runtime': 7.22.6 /media-typer@0.3.0: resolution: @@ -22322,7 +22334,6 @@ packages: } engines: { node: '>=0.10.0' } requiresBuild: true - dev: true /normalize-range@0.1.2: resolution: @@ -22396,7 +22407,7 @@ packages: engines: { node: '>=10' } dependencies: hosted-git-info: 3.0.8 - semver: 7.5.3 + semver: 7.5.4 validate-npm-package-name: 3.0.0 dev: true @@ -23117,7 +23128,6 @@ packages: engines: { node: '>=6' } dependencies: callsites: 3.1.0 - dev: true /parse-entities@2.0.0: resolution: @@ -23178,11 +23188,10 @@ packages: } engines: { node: '>=8' } dependencies: - '@babel/code-frame': 7.22.13 + '@babel/code-frame': 7.23.5 error-ex: 1.3.2 json-parse-even-better-errors: 2.3.1 lines-and-columns: 1.2.4 - dev: true /parse-numeric-range@1.3.0: resolution: @@ -24846,7 +24855,7 @@ packages: dependencies: object-assign: 4.1.1 react: 18.2.0 - react-is: 17.0.2 + react-is: 18.2.0 dev: true /react-side-effect@2.1.2(react@18.2.0): @@ -24888,7 +24897,7 @@ packages: peerDependencies: react: '>= 0.14.0' dependencies: - '@babel/runtime': 7.22.5 + '@babel/runtime': 7.22.6 highlight.js: 10.7.3 lowlight: 1.20.0 prismjs: 1.28.0 @@ -25967,6 +25976,7 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 + dev: true /semver@7.5.4: resolution: @@ -25977,7 +25987,6 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 - dev: true /send@0.18.0: resolution: @@ -26198,6 +26207,14 @@ packages: } engines: { node: '>=12' } + /slice-ansi@4.0.0: + resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==} + engines: {node: '>=10'} + dependencies: + ansi-styles: 4.3.0 + astral-regex: 2.0.0 + is-fullwidth-code-point: 3.0.0 + /slice-ansi@5.0.0: resolution: { @@ -28488,7 +28505,6 @@ packages: } dependencies: punycode: 2.3.1 - dev: true /url-loader@4.1.1(webpack@5.88.0): resolution: