From 8aac80d963523d7e0295c96cc8e725337aeb5405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Pires?= Date: Fri, 21 Jun 2024 13:18:36 +0100 Subject: [PATCH] fix tests; remove deprecated stylelint-config-slds; added @stylistic/stylelint-plugin; improve README; --- README.md | 15 ++- .../all-patterns-config/results.xml | 14 ++- .../all-patterns-config/src/.stylelintrc | 17 ++- docs/multiple-tests/no-crash/src/.stylelintrc | 5 +- .../with-config-file/results.xml | 54 ++++----- .../with-config-file/src/.stylelintrc | 71 ++++++----- package-lock.json | 113 ++++++++++-------- package.json | 11 +- .../scala/codacy/stylelint/Stylelint.scala | 12 +- 9 files changed, 177 insertions(+), 135 deletions(-) diff --git a/README.md b/README.md index 08f1fb9..7357995 100644 --- a/README.md +++ b/README.md @@ -7,19 +7,22 @@ Docker engine to allow Codacy to have [stylelint](https://github.com/stylelint/s ## Usage -You can create the docker by following these steps: +Create the docker: + +1. Generate tool binary -1) Generate base image: ```sh -docker build -t codacy-stylelint-base . +sbt stage ``` -2) Generate tool image: +2. Generate tool docker + ```sh -sbt docker:publishLocal +docker build -t codacy-stylelint . ``` -The docker is ran with the following command: + +Run docker: ```sh docker run -it -v $srcDir:/src : diff --git a/docs/multiple-tests/all-patterns-config/results.xml b/docs/multiple-tests/all-patterns-config/results.xml index a1b87ba..7ff1fad 100644 --- a/docs/multiple-tests/all-patterns-config/results.xml +++ b/docs/multiple-tests/all-patterns-config/results.xml @@ -1,9 +1,11 @@ - - - - - - + + + + + + + + diff --git a/docs/multiple-tests/all-patterns-config/src/.stylelintrc b/docs/multiple-tests/all-patterns-config/src/.stylelintrc index 465ff1a..3e8f1bf 100644 --- a/docs/multiple-tests/all-patterns-config/src/.stylelintrc +++ b/docs/multiple-tests/all-patterns-config/src/.stylelintrc @@ -1,17 +1,24 @@ { "extends": [ + "stylelint-config-css-modules", "stylelint-config-standard", - "stylelint-config-slds" + "stylelint-config-sass-guidelines", + "stylelint-config-standard-scss", + "stylelint-config-styled-components", + "stylelint-config-tailwindcss", + "stylelint-config-twbs-bootstrap", + "stylelint-prettier/recommended" ], "plugins":[ - "stylelint-order", - "stylelint-scss", + "@stylistic/stylelint-plugin", "stylelint-declaration-strict-value", + "stylelint-no-px", + "stylelint-scss", + "stylelint-selector-bem-pattern", + "stylelint-suitcss", "stylelint-selector-bem-pattern" ], "rules": { - "scale-unlimited/declaration-strict-value": "color", - "sh-waqar/declaration-use-variable": "/color/", "plugin/selector-bem-pattern": { "componentName": "[A-Z]+", "componentSelectors": { diff --git a/docs/multiple-tests/no-crash/src/.stylelintrc b/docs/multiple-tests/no-crash/src/.stylelintrc index b136597..835d723 100644 --- a/docs/multiple-tests/no-crash/src/.stylelintrc +++ b/docs/multiple-tests/no-crash/src/.stylelintrc @@ -1,5 +1,8 @@ { + "plugins": [ + "@stylistic/stylelint-plugin" + ], "rules": { - "color-hex-case": "lower" + "@stylistic/color-hex-case": "lower" } } diff --git a/docs/multiple-tests/with-config-file/results.xml b/docs/multiple-tests/with-config-file/results.xml index 5a20b9b..7a2b48e 100644 --- a/docs/multiple-tests/with-config-file/results.xml +++ b/docs/multiple-tests/with-config-file/results.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/multiple-tests/with-config-file/src/.stylelintrc b/docs/multiple-tests/with-config-file/src/.stylelintrc index 74900f1..83fd6cd 100644 --- a/docs/multiple-tests/with-config-file/src/.stylelintrc +++ b/docs/multiple-tests/with-config-file/src/.stylelintrc @@ -1,50 +1,55 @@ { - "extends": "stylelint-config-standard", + "extends": [ + "stylelint-config-standard" + ], + "plugins": [ + "@stylistic/stylelint-plugin" + ], "rules": { - "color-hex-case": "lower", + "@stylistic/block-closing-brace-empty-line-before": "never", + "@stylistic/block-closing-brace-newline-before": "always", + "block-no-empty": true, + "@stylistic/block-opening-brace-newline-after": "always", + "@stylistic/color-hex-case": "lower", "color-named": "never" , "color-no-invalid-hex": true, + "@stylistic/declaration-bang-space-after": "never", + "@stylistic/declaration-bang-space-before": "always", + "declaration-block-no-duplicate-properties": true, + "declaration-block-no-redundant-longhand-properties": true, + "declaration-block-no-shorthand-property-overrides": true, + "@stylistic/declaration-block-semicolon-newline-after": "always", + "declaration-block-single-line-max-declarations": 1, + "@stylistic/declaration-block-trailing-semicolon": "always", + "@stylistic/declaration-colon-newline-after": "always-multi-line", + "@stylistic/declaration-colon-space-after": "always", + "@stylistic/declaration-colon-space-before": "never", + "declaration-empty-line-before": "never", + "declaration-no-important": true, "font-weight-notation": "numeric", "function-calc-no-unspaced-operator": true, - "function-comma-newline-after": "never-multi-line", - "function-comma-space-after": "always", - "function-comma-space-before": "never", + "@stylistic/function-comma-newline-after": "never-multi-line", + "@stylistic/function-comma-space-after": "always", + "@stylistic/function-comma-space-before": "never", "function-linear-gradient-no-nonstandard-direction": true, "function-name-case": "lower", - "function-parentheses-newline-inside": "never-multi-line", - "function-parentheses-space-inside": "never", + "@stylistic/function-parentheses-newline-inside": "never-multi-line", + "@stylistic/function-parentheses-space-inside": "never", "function-url-scheme-disallowed-list": "data", "function-url-no-scheme-relative": true, "function-url-quotes": "always", - "function-whitespace-after": "always", - "number-leading-zero": "never", - "number-no-trailing-zeros": true, + "@stylistic/function-whitespace-after": "always", + "@stylistic/number-leading-zero": "never", + "@stylistic/number-no-trailing-zeros": true, + "@stylistic/property-case": "lower", + "property-no-unknown": true, + "shorthand-property-no-redundant-values": true, "string-no-newline": true, - "string-quotes": "single", + "@stylistic/string-quotes": "single", "time-min-milliseconds": 100, - "unit-case": "lower", + "@stylistic/unit-case": "lower", "unit-no-unknown": true, - "value-keyword-case": "lower", - "shorthand-property-no-redundant-values": true, - "property-case": "lower", - "property-no-unknown": true, - "declaration-bang-space-after": "never", - "declaration-bang-space-before": "always", - "declaration-colon-newline-after": "always-multi-line", - "declaration-colon-space-after": "always", - "declaration-colon-space-before": "never", - "declaration-empty-line-before": "never", - "declaration-no-important": true, - "declaration-block-no-duplicate-properties": true, - "declaration-block-no-redundant-longhand-properties": true, - "declaration-block-no-shorthand-property-overrides": true, - "declaration-block-semicolon-newline-after": "always", - "declaration-block-single-line-max-declarations": 1, - "declaration-block-trailing-semicolon": "always", - "block-closing-brace-empty-line-before": "never", - "block-no-empty": true, - "block-opening-brace-newline-after": "always", - "block-closing-brace-newline-before": "always" + "value-keyword-case": "lower" }, "overrides": [ { diff --git a/package-lock.json b/package-lock.json index 8e97563..1a87156 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "packages": { "": { "dependencies": { + "@stylistic/stylelint-plugin": "^2.1.2", "postcss": "^8.4.38", "postcss-less": "^6.0.0", "postcss-safe-parser": "^7.0.0", @@ -17,8 +18,7 @@ "stylelint": "^16.6.1", "stylelint-config-css-modules": "^4.4.0", "stylelint-config-sass-guidelines": "^11.1.0", - "stylelint-config-slds": "^1.0.8", - "stylelint-config-standard": "^36.0.0", + "stylelint-config-standard": "^36.0.1", "stylelint-config-standard-scss": "^13.1.0", "stylelint-config-styled-components": "^0.1.1", "stylelint-config-tailwindcss": "^0.0.7", @@ -26,9 +26,12 @@ "stylelint-declaration-strict-value": "^1.10.4", "stylelint-no-px": "^2.0.0", "stylelint-prettier": "^5.0.0", - "stylelint-scss": "^6.3.1", + "stylelint-scss": "^6.3.2", "stylelint-selector-bem-pattern": "^4.0.0", "stylelint-suitcss": "^5.0.0" + }, + "engines": { + "node": ">=20.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -380,18 +383,18 @@ } }, "node_modules/@stylistic/stylelint-plugin": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@stylistic/stylelint-plugin/-/stylelint-plugin-2.1.1.tgz", - "integrity": "sha512-xqHTmQZN7EbnFDW7jw0rAsdFNO4IRqvXhrh3qhUlIwF/x09Zm7kgs/ADktHxsTJYcw346PpGihsB0t4pZhpeHw==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@stylistic/stylelint-plugin/-/stylelint-plugin-2.1.2.tgz", + "integrity": "sha512-JsSqu0Y3vsX+PBl+DwULxC0cIv9C1yIcq1MXkx7pBOGtTqU26a75I8MPYMiEYvrsXgsKLi65xVgy1iLVSZquJA==", "dependencies": { - "@csstools/css-parser-algorithms": "^2.5.0", - "@csstools/css-tokenizer": "^2.2.3", - "@csstools/media-query-list-parser": "^2.1.7", + "@csstools/css-parser-algorithms": "^2.6.1", + "@csstools/css-tokenizer": "^2.2.4", + "@csstools/media-query-list-parser": "^2.1.9", "is-plain-object": "^5.0.0", - "postcss-selector-parser": "^6.0.15", + "postcss-selector-parser": "^6.0.16", "postcss-value-parser": "^4.2.0", "style-search": "^0.1.0", - "stylelint": "^16.2.1" + "stylelint": "^16.4.0" }, "engines": { "node": "^18.12 || >=20.9" @@ -3000,14 +3003,24 @@ } }, "node_modules/stylelint-config-recommended": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-14.0.0.tgz", - "integrity": "sha512-jSkx290CglS8StmrLp2TxAppIajzIBZKYm3IxT89Kg6fGlxbPiTiyH9PS5YUuVAFwaJLl1ikiXX0QWjI0jmgZQ==", + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-14.0.1.tgz", + "integrity": "sha512-bLvc1WOz/14aPImu/cufKAZYfXs/A/owZfSMZ4N+16WGXLoX5lOir53M6odBxvhgmgdxCVnNySJmZKx73T93cg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/stylelint" + }, + { + "type": "github", + "url": "https://github.com/sponsors/stylelint" + } + ], "engines": { "node": ">=18.12.0" }, "peerDependencies": { - "stylelint": "^16.0.0" + "stylelint": "^16.1.0" } }, "node_modules/stylelint-config-recommended-scss": { @@ -3048,17 +3061,22 @@ "stylelint": "^16.1.0" } }, - "node_modules/stylelint-config-slds": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/stylelint-config-slds/-/stylelint-config-slds-1.0.8.tgz", - "integrity": "sha512-oqBKmbYkwPoqwJoa5xVlL4ZF6xBVQe3ZDLypA6LX7BOnvS3nmuvhXw9v61N4haR5TyaNSXl56ylWRZOVeFdgCA==" - }, "node_modules/stylelint-config-standard": { - "version": "36.0.0", - "resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-36.0.0.tgz", - "integrity": "sha512-3Kjyq4d62bYFp/Aq8PMKDwlgUyPU4nacXsjDLWJdNPRUgpuxALu1KnlAHIj36cdtxViVhXexZij65yM0uNIHug==", + "version": "36.0.1", + "resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-36.0.1.tgz", + "integrity": "sha512-8aX8mTzJ6cuO8mmD5yon61CWuIM4UD8Q5aBcWKGSf6kg+EC3uhB+iOywpTK4ca6ZL7B49en8yanOFtUW0qNzyw==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/stylelint" + }, + { + "type": "github", + "url": "https://github.com/sponsors/stylelint" + } + ], "dependencies": { - "stylelint-config-recommended": "^14.0.0" + "stylelint-config-recommended": "^14.0.1" }, "engines": { "node": ">=18.12.0" @@ -3182,9 +3200,9 @@ } }, "node_modules/stylelint-scss": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-6.3.1.tgz", - "integrity": "sha512-w/czBoWUZxJNk5fBRPODcXSN4qcPv3WHjTSSpFovVY+TE3MZTMR0yRlbmaDYrm8tTWHvpwQAuEBZ0lk2wwkboQ==", + "version": "6.3.2", + "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-6.3.2.tgz", + "integrity": "sha512-pNk9mXOVKkQtd+SROPC9io8ISSgX+tOVPhFdBE+LaKQnJMLdWPbGKAGYv4Wmf/RrnOjkutunNTN9kKMhkdE5qA==", "dependencies": { "known-css-properties": "^0.31.0", "postcss-media-query-parser": "^0.2.3", @@ -4043,18 +4061,18 @@ } }, "@stylistic/stylelint-plugin": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@stylistic/stylelint-plugin/-/stylelint-plugin-2.1.1.tgz", - "integrity": "sha512-xqHTmQZN7EbnFDW7jw0rAsdFNO4IRqvXhrh3qhUlIwF/x09Zm7kgs/ADktHxsTJYcw346PpGihsB0t4pZhpeHw==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@stylistic/stylelint-plugin/-/stylelint-plugin-2.1.2.tgz", + "integrity": "sha512-JsSqu0Y3vsX+PBl+DwULxC0cIv9C1yIcq1MXkx7pBOGtTqU26a75I8MPYMiEYvrsXgsKLi65xVgy1iLVSZquJA==", "requires": { - "@csstools/css-parser-algorithms": "^2.5.0", - "@csstools/css-tokenizer": "^2.2.3", - "@csstools/media-query-list-parser": "^2.1.7", + "@csstools/css-parser-algorithms": "^2.6.1", + "@csstools/css-tokenizer": "^2.2.4", + "@csstools/media-query-list-parser": "^2.1.9", "is-plain-object": "^5.0.0", - "postcss-selector-parser": "^6.0.15", + "postcss-selector-parser": "^6.0.16", "postcss-value-parser": "^4.2.0", "style-search": "^0.1.0", - "stylelint": "^16.2.1" + "stylelint": "^16.4.0" } }, "@types/json-schema": { @@ -5969,9 +5987,9 @@ } }, "stylelint-config-recommended": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-14.0.0.tgz", - "integrity": "sha512-jSkx290CglS8StmrLp2TxAppIajzIBZKYm3IxT89Kg6fGlxbPiTiyH9PS5YUuVAFwaJLl1ikiXX0QWjI0jmgZQ==", + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-14.0.1.tgz", + "integrity": "sha512-bLvc1WOz/14aPImu/cufKAZYfXs/A/owZfSMZ4N+16WGXLoX5lOir53M6odBxvhgmgdxCVnNySJmZKx73T93cg==", "requires": {} }, "stylelint-config-recommended-scss": { @@ -5993,17 +6011,12 @@ "stylelint-scss": "^6.2.1" } }, - "stylelint-config-slds": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/stylelint-config-slds/-/stylelint-config-slds-1.0.8.tgz", - "integrity": "sha512-oqBKmbYkwPoqwJoa5xVlL4ZF6xBVQe3ZDLypA6LX7BOnvS3nmuvhXw9v61N4haR5TyaNSXl56ylWRZOVeFdgCA==" - }, "stylelint-config-standard": { - "version": "36.0.0", - "resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-36.0.0.tgz", - "integrity": "sha512-3Kjyq4d62bYFp/Aq8PMKDwlgUyPU4nacXsjDLWJdNPRUgpuxALu1KnlAHIj36cdtxViVhXexZij65yM0uNIHug==", + "version": "36.0.1", + "resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-36.0.1.tgz", + "integrity": "sha512-8aX8mTzJ6cuO8mmD5yon61CWuIM4UD8Q5aBcWKGSf6kg+EC3uhB+iOywpTK4ca6ZL7B49en8yanOFtUW0qNzyw==", "requires": { - "stylelint-config-recommended": "^14.0.0" + "stylelint-config-recommended": "^14.0.1" } }, "stylelint-config-standard-scss": { @@ -6072,9 +6085,9 @@ } }, "stylelint-scss": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-6.3.1.tgz", - "integrity": "sha512-w/czBoWUZxJNk5fBRPODcXSN4qcPv3WHjTSSpFovVY+TE3MZTMR0yRlbmaDYrm8tTWHvpwQAuEBZ0lk2wwkboQ==", + "version": "6.3.2", + "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-6.3.2.tgz", + "integrity": "sha512-pNk9mXOVKkQtd+SROPC9io8ISSgX+tOVPhFdBE+LaKQnJMLdWPbGKAGYv4Wmf/RrnOjkutunNTN9kKMhkdE5qA==", "requires": { "known-css-properties": "^0.31.0", "postcss-media-query-parser": "^0.2.3", diff --git a/package.json b/package.json index eced951..9beb960 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,16 @@ { + "engines": { + "node": ">=20.0.0" + }, "scripts": { - "build:docker": "docker build -t codacy-stylelint-base .", + "build:docker": "docker build -t codacy-stylelint .", "build:docs": "sbt doc-generator/run", - "test": "sbt scalafmtCheckAll scalafmtSbtCheck doc-generator/run stage", + "test": "sbt 'scalafmtCheckAll scalafmtSbtCheck doc-generator/run stage'", "preupgrade": "npx npm-check-updates -u", - "upgrade": "npm install --omit=dev" + "upgrade": "npm install" }, "dependencies": { + "@stylistic/stylelint-plugin": "^2.1.2", "postcss": "^8.4.38", "postcss-less": "^6.0.0", "postcss-safe-parser": "^7.0.0", @@ -19,7 +23,6 @@ "stylelint": "^16.6.1", "stylelint-config-css-modules": "^4.4.0", "stylelint-config-sass-guidelines": "^11.1.0", - "stylelint-config-slds": "^1.0.8", "stylelint-config-standard": "^36.0.0", "stylelint-config-standard-scss": "^13.1.0", "stylelint-config-styled-components": "^0.1.1", diff --git a/src/main/scala/codacy/stylelint/Stylelint.scala b/src/main/scala/codacy/stylelint/Stylelint.scala index 5d6dd9f..0887bed 100644 --- a/src/main/scala/codacy/stylelint/Stylelint.scala +++ b/src/main/scala/codacy/stylelint/Stylelint.scala @@ -96,15 +96,22 @@ object Stylelint extends Tool { val command = executableFile ++ fileArgument ++ configurationFile ++ configurationBaseDir ++ formatter ++ options - CommandRunner.exec(command, Option(File(source.path).toJava)).fold(Failure(_), Success(_)) + println(s"Running stylelint with command: ${command.mkString(" ")}") + + val commandResult = CommandRunner.exec(command, Option(File(source.path).toJava)).fold(Failure(_), Success(_)) + println(commandResult) + commandResult } implicit val warningResultFmt: Format[StylelintPatternResult] = Json.format[StylelintPatternResult] implicit val resultFmt: Format[StylelintResult] = Json.format[StylelintResult] def parseCommandResult(commandResult: Try[CommandResult], targetFiles: List[String]): Try[List[StylelintResult]] = { + println(commandResult) + commandResult.flatMap { - case CommandResult(ExitCodes.NO_ISSUES | ExitCodes.DETECTED_ISSUES, stdOut, _) => parseJson(stdOut) + case CommandResult(ExitCodes.NO_ISSUES | ExitCodes.DETECTED_ISSUES, _, results) => + parseJson(results) case CommandResult(exitCode, stdOut, stdErr) => val toolErrorMessage = s"""Stylelint exited with code ${printExitCode(exitCode)} @@ -132,7 +139,6 @@ object Stylelint extends Tool { val errorString = s"""Could not parse results json: |$jsonString - |$jsonLines | |Exception: ${err.getMessage} """.stripMargin