diff --git a/.github/dependabot.yml b/.github/dependabot.yml index abf320b6..d04be6eb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,7 +4,7 @@ updates: directory: "/" schedule: interval: daily - timezone: Europe/Lisbon + timezone: Europe/Lisbon open-pull-requests-limit: 10 ignore: - dependency-name: stylelint-config-standard @@ -12,4 +12,4 @@ updates: - 21.0.0 - dependency-name: stylelint-config-recommended versions: - - 4.0.0 + - 4.0.0 diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml new file mode 100644 index 00000000..e4eb8e80 --- /dev/null +++ b/.github/workflows/codacy.yml @@ -0,0 +1,61 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# This workflow checks out code, performs a Codacy security scan +# and integrates the results with the +# GitHub Advanced Security code scanning feature. For more information on +# the Codacy security scan action usage and parameters, see +# https://github.com/codacy/codacy-analysis-cli-action. +# For more information on Codacy Analysis CLI in general, see +# https://github.com/codacy/codacy-analysis-cli. + +name: Codacy Security Scan + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '18 1 * * 3' + +permissions: + contents: read + +jobs: + codacy-security-scan: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + name: Codacy Security Scan + runs-on: ubuntu-latest + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout code + uses: actions/checkout@v3 + + # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis + - name: Run Codacy Analysis CLI + uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b + with: + # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository + # You can also omit the token and run the tools that support default configurations + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + verbose: true + output: results.sarif + format: sarif + # Adjust severity of non-security issues + gh-code-scanning-compat: true + # Force 0 exit code to allow SARIF file generation + # This will handover control about PR rejection to the GitHub side + max-allowed-issues: 2147483647 + + # Upload the SARIF file generated in the previous step + - name: Upload SARIF results file + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: results.sarif diff --git a/.gitignore b/.gitignore index 8d0c405a..a19cdb71 100644 --- a/.gitignore +++ b/.gitignore @@ -2,15 +2,15 @@ /logs/ /project/*-shim.sbt /project/project/ -/project/target/ +/project/target/ target /.bsp .idea .metals -project/metals.sbt +project/metals.sbt .bloop .DS_Store *.iml -node_modules/ +node_modules/ .stylelint-version -.vscode/ +.vscode/ diff --git a/Dockerfile b/Dockerfile index 341087ba..5ea9f0d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ FROM alpine:3.18 - + WORKDIR /workdir COPY package*.json ./ RUN adduser -u 2004 -D docker &&\ apk --no-cache add openjdk11-jre-headless bash nodejs npm &&\ npm install --legacy-peer-deps --omit=dev &&\ - apk del npm -COPY docs /docs + apk del npm \ +COPY docs /docss COPY target/universal/stage/ /workdir/ RUN chmod +x /workdir/bin/codacy-stylelint USER docker -WORKDIR /src +WORKDIR /src/main ENTRYPOINT ["/workdir/bin/codacy-stylelint"] diff --git a/README.md b/README.md index cd693ff9..e0c77563 100644 --- a/README.md +++ b/README.md @@ -10,34 +10,45 @@ Docker engine to allow Codacy to have [stylelint](https://github.com/stylelint/s ## Usage You can create the docker by following these steps: +Random content1 +Random Content2 +Random Content3 -1) Generate base image: + + + + + +1) Generate base image content1: ``` docker build -t codacy-stylelint-base . ``` -2) Generate tool image: + ``` sbt docker:publishLocal ``` -The docker is ran with the following command: +The docker is ran with the following command: new changes are here. ``` + docker run -it -v $srcDir:/src : ``` +2) Generate tool images: + ## Docs + [Tool Developer Guide](https://support.codacy.com/hc/en-us/articles/207994725-Tool-Developer-Guide) [Tool Developer Guide - Using Scala](https://support.codacy.com/hc/en-us/articles/207280379-Tool-Developer-Guide-Using-Scala) ## Test -We use the [codacy-plugins-test](https://github.com/codacy/codacy-plugins-test) to test our external tools integration. -You can follow the instructions there to make sure your tool is working as expected. - +Hello, we use the [codacy-plugins-test](https://github.com/codacy/codacy-plugins-test) to test our external tools integration. +New content ## Update tool version The tool is dependabot friendly, so it is automatically updated. @@ -48,9 +59,10 @@ The tool is dependabot friendly, so it is automatically updated. sbt "doc-generator/run" ``` + ## What is Codacy -[Codacy](https://www.codacy.com/) is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews. +[Codacy](https://www.codacy.com/content) is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews. ### Among Codacy’s features diff --git a/build.sbt b/builds-new.sbt similarity index 94% rename from build.sbt rename to builds-new.sbt index b2db89b6..7c429d61 100644 --- a/build.sbt +++ b/builds-new.sbt @@ -3,10 +3,10 @@ ThisBuild / scalaVersion := "2.13.11" ThisBuild / libraryDependencies += "com.codacy" %% "codacy-engine-scala-seed" % "6.1.0" ThisBuild / libraryDependencies += "com.github.pathikrit" %% "better-files" % "3.9.2" -name := "codacy-stylelint" +name := "codacy-stylelint"s lazy val `doc-generator` = project.settings(libraryDependencies += "com.vladsch.flexmark" % "flexmark-all" % "0.64.6") enablePlugins(JavaAppPackaging) - +s Universal / javaOptions ++= Seq("-XX:+UseG1GC", "-XX:+UseStringDeduplication", "-XX:MaxRAMPercentage=90.0") diff --git a/doc-generator/sample/content.json.txt b/doc-generator/sample/content.json.txt new file mode 100644 index 00000000..f26b09d2 --- /dev/null +++ b/doc-generator/sample/content.json.txt @@ -0,0 +1,3 @@ +{ +"language": "python" +} \ No newline at end of file diff --git a/docs/multiple-tests/pass-default-parameter/patterns.xml b/docs/multiple-tests/pass-default-parameter/patterns.xml index 341377b3..211cc674 100644 --- a/docs/multiple-tests/pass-default-parameter/patterns.xml +++ b/docs/multiple-tests/pass-default-parameter/patterns.xml @@ -1,8 +1,8 @@ - + - + --> diff --git a/docs/multiple-tests/pass-default-parameter/src/test2.css b/docs/multiple-tests/pass-default-parameter/src/test2.css new file mode 100644 index 00000000..1028c5d4 --- /dev/null +++ b/docs/multiple-tests/pass-default-parameter/src/test2.css @@ -0,0 +1,4 @@ +.hEad { + + +} diff --git a/package.json b/package.json index 42c58439..815bd8b0 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,15 @@ "test": "sbt scalafmtCheckAll scalafmtSbtCheck doc-generator/run stage" }, "dependencies": { - "postcss": "^8.4.29", + "postcss-new": "^8.4.30", "postcss-less": "^6.0.0", "postcss-safe-parser": "^6.0.0", "postcss-sass": "^0.5.0", - "postcss-scss": "^4.0.7", "postcss-styled": "^0.34.0", "postcss-styled-syntax": "^0.4.0", "postcss-syntax": "^0.36.2", + "postcss-syntax": "^0.36.2", + "age": "19", "prettier": "^3.0.3", "stylelint": "^15.10.3", "stylelint-config-css-modules": "^4.3.0", @@ -28,6 +29,7 @@ "stylelint-prettier": "^4.0.2", "stylelint-scss": "^5.1.0", "stylelint-selector-bem-pattern": "^3.0.1", - "stylelint-suitcss": "^5.0.0" + "stylelint-suitcss": "^5.0.0", + "city": "delhi" } } diff --git a/project/build.properties b/project/build.properties index 875b706a..dedcd6a9 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1,13 @@ +api.secretKey=superSecretKey123 +db.encryptionKey=anotherSecretKey456 + sbt.version=1.9.2 +db.password= +api.timeout=5000 + + +# Comments with excessive length, making them harder to read and maintain +# This is a very long comment that goes on and on without any real need for it to be this long, +# but it is here to demonstrate the kind of code smell that can occur when comments are not concise +# and to the point, making it harder for developers to quickly understand the context or purpose +# of the property or configuration being described. diff --git a/project/plugin.sbt b/project/plugin.sbt new file mode 100644 index 00000000..3ab11a30 --- /dev/null +++ b/project/plugin.sbt @@ -0,0 +1,7 @@ +resolvers += Resolver.jcenterRepo +addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "25.1.1") + +//addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9") + +// Coverage +//addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.2") diff --git a/project/plugins.sbt b/project/plugins.sbt deleted file mode 100644 index 24022fc4..00000000 --- a/project/plugins.sbt +++ /dev/null @@ -1,7 +0,0 @@ -resolvers += Resolver.jcenterRepo -addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "25.1.1") - -addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9") - -// Coverage -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.2") diff --git a/src/main/scala/codacy/Engine.scala b/src/main/scala/codacy-new/Engine-4.scala similarity index 79% rename from src/main/scala/codacy/Engine.scala rename to src/main/scala/codacy-new/Engine-4.scala index 8e8f3585..0ac71c18 100644 --- a/src/main/scala/codacy/Engine.scala +++ b/src/main/scala/codacy-new/Engine-4.scala @@ -4,3 +4,6 @@ import codacy.stylelint.Stylelint import com.codacy.tools.scala.seed.DockerEngine object Engine extends DockerEngine(Stylelint)() + new chnages for sample-3 + + new content \ No newline at end of file diff --git a/src/main/scala/codacy-new/Hellos-again-9.xml b/src/main/scala/codacy-new/Hellos-again-9.xml new file mode 100644 index 00000000..dd0236b4 --- /dev/null +++ b/src/main/scala/codacy-new/Hellos-again-9.xml @@ -0,0 +1,9 @@ + + + + + +sss + + +new conten 5 8 9 10 \ No newline at end of file diff --git a/src/main/scala/codacy/stylelint/ToolOutput.scala b/src/main/scala/codacy-new/stylelint/ToolNewOutput-NewMaster.scala similarity index 70% rename from src/main/scala/codacy/stylelint/ToolOutput.scala rename to src/main/scala/codacy-new/stylelint/ToolNewOutput-NewMaster.scala index 6408ad42..f94c0c99 100644 --- a/src/main/scala/codacy/stylelint/ToolOutput.scala +++ b/src/main/scala/codacy-new/stylelint/ToolNewOutput-NewMaster.scala @@ -1,5 +1,6 @@ package codacy.stylelint +case class StylelintPatternResult(line: Int, column: Int, rule: String, severities: String, text: String) -case class StylelintPatternResult(line: Int, column: Int, rule: String, severity: String, text: String) -case class StylelintResult(source: String, warnings: List[StylelintPatternResult]) +sss +case class StylelintResult(source: String, warnings: List[StylelintPatternResults]) diff --git a/src/main/scala/codacy/stylelint/Stylelint.scala b/src/main/scala/codacy/stylelint/Stylelint.scala deleted file mode 100644 index ed36f62c..00000000 --- a/src/main/scala/codacy/stylelint/Stylelint.scala +++ /dev/null @@ -1,158 +0,0 @@ -package codacy.stylelint - -import java.nio.file.{Path, Paths} - -import better.files._ -import com.codacy.plugins.api.results.{Pattern, Result, Tool} -import com.codacy.plugins.api.{Options, Source} -import com.codacy.tools.scala.seed.utils.{CommandResult, CommandRunner} -import com.codacy.tools.scala.seed.utils.FileHelper._ -import com.codacy.tools.scala.seed.utils.ToolHelper._ -import play.api.libs.json._ - -import scala.util.{Failure, Success, Try} - -object Stylelint extends Tool { - - private lazy val configFileNames = Set( - ".stylelintrc", - ".stylelintrc.json", - ".stylelintrc.yaml", - ".stylelintrc.yml", - ".stylelintrc.js", - "stylelint.config.js") - - //from https://stylelint.io/user-guide/usage/cli/#exit-codes - private object ExitCodes { - val NO_ISSUES = 0 - val EXECUTION_ERROR = 1 - val DETECTED_ISSUES = 2 - val CONFIGURATION_ERROR = 78 - } - - override def apply( - source: Source.Directory, - configuration: Option[List[Pattern.Definition]], - files: Option[Set[Source.File]], - options: Map[Options.Key, Options.Value])(implicit specification: Tool.Specification): Try[List[Result]] = { - - files match { - case Some(set) if set.isEmpty => - Success(List.empty) - case _ => - val configFilePath = getConfigFile(source, configuration.withDefaultParameters) - val commandResult = run(source, configFilePath, files) - commandResult match { - case Failure(err) => - Failure(new Exception(s"Could not run stylelint: ${err.getCause}")) - case _ => - val filesArgument = files.fold(List("All"))(_.map(_.path).toList) - val parsedResults = parseCommandResult(commandResult, filesArgument) - - convertToResult(parsedResults) - } - } - } - - def checkForExistingConfigFile(source: Source.Directory): Option[Path] = { - findConfigurationFile(Paths.get(source.path), configFileNames) - } - - def getConfigFile(source: Source.Directory, configuration: Option[List[Pattern.Definition]]): Path = { - configuration.map { config => - val patterns = config.map { pattern => - val parameter = pattern.parameters.headOption.map { param => - val parameterValue: JsValue = param.value - parameterValue - }.getOrElse(JsNull) - - (pattern.patternId.value, parameter) - } - File - .newTemporaryFile("codacy-stylelint", ".json") - .write(Json.prettyPrint(Json.toJson(JsObject(Seq(("rules", JsObject(patterns))))))) - .path - }.orElse { - checkForExistingConfigFile(source) - }.getOrElse { - File - .newTemporaryFile("codacy-stylelint", ".json") - .write(Json.prettyPrint(Json.toJson(JsObject(Seq(("extends", JsString("stylelint-config-standard"))))))) - .path - } - } - - def run(source: Source.Directory, configFilePath: Path, filesOpt: Option[Set[Source.File]]): Try[CommandResult] = { - val nodeModulesDir = "/workdir/node_modules" - val executableFile = List(s"$nodeModulesDir/stylelint/bin/stylelint.mjs") - val fileArgument = filesOpt - .map(files => files.map(_.path)) - .getOrElse(List("**/**.{css,scss,less,sass}", "--custom-syntax", "postcss-syntax")) - - val configurationBaseDir = List("--config-basedir", nodeModulesDir) - val configurationFile = List("--config", configFilePath.toString) - val formatter = List("--formatter", "json") - val options = List("--allow-empty-input") - - val command = executableFile ++ fileArgument ++ configurationFile ++ configurationBaseDir ++ formatter ++ options - - CommandRunner.exec(command, Option(File(source.path).toJava)).fold(Failure(_), Success(_)) - } - - 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]] = { - commandResult.flatMap { - case CommandResult(ExitCodes.NO_ISSUES | ExitCodes.DETECTED_ISSUES, stdOut, _) => parseJson(stdOut) - case CommandResult(exitCode, stdOut, stdErr) => - val toolErrorMessage = - s"""Stylelint exited with code ${printExitCode(exitCode)} - | - targeting files: $targetFiles - | - stderr: $stdErr - | - stdout: $stdOut - |""".stripMargin - scala.util.Failure(new Exception(toolErrorMessage)) - } - } - - def printExitCode(value: Int) = value match { - case ExitCodes.EXECUTION_ERROR => - s"$value - something unknown went wrong when executing the tool" - case ExitCodes.CONFIGURATION_ERROR => - s"$value - there was some problem with the configuration file" - case _ => - s"$value - unknown error" - } - - def parseJson(jsonLines: List[String]): Try[List[StylelintResult]] = { - val jsonString = jsonLines.mkString("\n") - Try(Json.parse(jsonString).as[List[StylelintResult]]).recoverWith { - case err => - val errorString = - s"""Could not parse results json: - | - |Exception: ${err.getMessage} - | - |Json: - |$jsonString - """.stripMargin - Failure(new Exception(errorString)) - } - } - - def convertToResult(parsedResults: Try[List[StylelintResult]]): Try[List[Result]] = { - parsedResults.map { results => - results.flatMap { fileResultsData => - fileResultsData.warnings.map { resultData => - Result.Issue( - Source.File(fileResultsData.source), - Result.Message(resultData.text), - Pattern.Id(resultData.rule), - Source.Line(resultData.line)) - } - } - } - } - -}