From 5032e0c67792838d6754d172301e2373cf68deb7 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 5 Oct 2021 21:27:30 +0200 Subject: ci(web): add eslint and stylelint to sonar --- language-web/.eslintrc.ci.js | 33 +++++++++++++++++++++++++++++++++ language-web/.eslintrc.js | 32 ++++---------------------------- language-web/build.gradle | 33 ++++++++++++++++++--------------- language-web/package.json | 8 +++++--- language-web/yarn.lock | 5 +++++ 5 files changed, 65 insertions(+), 46 deletions(-) create mode 100644 language-web/.eslintrc.ci.js (limited to 'language-web') diff --git a/language-web/.eslintrc.ci.js b/language-web/.eslintrc.ci.js new file mode 100644 index 00000000..b4c83bb8 --- /dev/null +++ b/language-web/.eslintrc.ci.js @@ -0,0 +1,33 @@ +// Loosely based on +// https://github.com/iamturns/create-exposed-app/blob/f14e435b8ce179c89cce3eea89e56202153a53da/.eslintrc.js +module.exports = { + plugins: [ + '@typescript-eslint', + ], + extends: [ + 'airbnb', + 'airbnb-typescript', + 'airbnb/hooks', + 'plugin:@typescript-eslint/recommended', + 'plugin:@typescript-eslint/recommended-requiring-type-checking', + ], + parserOptions: { + project: './tsconfig.json', + }, + rules: { + // https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html + 'import/prefer-default-export': 'off', + 'import/no-default-export': 'error', + // propTypes are for runtime validation, but we rely on TypeScript for build-time validation: + // https://github.com/yannickcr/eslint-plugin-react/issues/2275#issuecomment-492003857 + 'react/prop-types': 'off', + // Make sure switches are exhaustive: https://stackoverflow.com/a/60166264 + 'default-case': 'off', + '@typescript-eslint/switch-exhaustiveness-check': 'error', + }, + ignorePatterns: [ + '*.js', + 'build/**/*', + 'src/main/js/xtext/**/*', + ], +}; diff --git a/language-web/.eslintrc.js b/language-web/.eslintrc.js index b4c83bb8..810a5ccd 100644 --- a/language-web/.eslintrc.js +++ b/language-web/.eslintrc.js @@ -1,33 +1,9 @@ -// Loosely based on -// https://github.com/iamturns/create-exposed-app/blob/f14e435b8ce179c89cce3eea89e56202153a53da/.eslintrc.js module.exports = { plugins: [ - '@typescript-eslint', + 'sonarjs', ], extends: [ - 'airbnb', - 'airbnb-typescript', - 'airbnb/hooks', - 'plugin:@typescript-eslint/recommended', - 'plugin:@typescript-eslint/recommended-requiring-type-checking', + './.eslintrc.ci.js', + 'plugin:sonarjs/recommended', ], - parserOptions: { - project: './tsconfig.json', - }, - rules: { - // https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html - 'import/prefer-default-export': 'off', - 'import/no-default-export': 'error', - // propTypes are for runtime validation, but we rely on TypeScript for build-time validation: - // https://github.com/yannickcr/eslint-plugin-react/issues/2275#issuecomment-492003857 - 'react/prop-types': 'off', - // Make sure switches are exhaustive: https://stackoverflow.com/a/60166264 - 'default-case': 'off', - '@typescript-eslint/switch-exhaustiveness-check': 'error', - }, - ignorePatterns: [ - '*.js', - 'build/**/*', - 'src/main/js/xtext/**/*', - ], -}; +} diff --git a/language-web/build.gradle b/language-web/build.gradle index 0403bb3d..526ba2da 100644 --- a/language-web/build.gradle +++ b/language-web/build.gradle @@ -27,9 +27,11 @@ def serverMainClass = 'tools.refinery.language.web.ServerLauncher' apply plugin: 'org.siouan.frontend-jdk11' import org.siouan.frontendgradleplugin.infrastructure.gradle.RunNpmYarn +def nodeDirectory = "${rootDir}/.gradle/node" + frontend { nodeVersion = project.ext.nodeVersion - nodeInstallDirectory = file("${rootDir}/.gradle/node") + nodeInstallDirectory = file(nodeDirectory) yarnEnabled = true yarnVersion = project.ext.yarnVersion yarnInstallDirectory = file("${rootDir}/.gradle/yarn") @@ -49,23 +51,16 @@ assembleFrontend.configure { outputs.dir productionResources } -tasks.register('webpackStats', RunNpmYarn) { - dependsOn installFrontend - dependsOn generateXtextLanguage - inputs.dir 'src/main/css' - inputs.dir 'src/main/html' - inputs.dir 'src/main/js' - inputs.dir "${buildDir}/generated/sources/xtext/js" - inputs.files('package.json', 'yarn.lock', 'webpack.config.js') - outputs.file "${buildDir}/webpack/stats.json" - script = 'run stats' -} - def eslint = tasks.register('eslint', RunNpmYarn) { dependsOn installFrontend inputs.dir 'src/main/js' inputs.files('.eslintrc.js', 'tsconfig.json') - script = 'run check:eslint' + if (project.hasProperty('ci')) { + outputs.file "${buildDir}/eslint.json" + script = 'run check:eslint:ci' + } else { + script = 'run check:eslint' + } group = 'verification' description = 'Check for TypeScript errors.' } @@ -74,7 +69,12 @@ def stylelint = tasks.register('stylelint', RunNpmYarn) { dependsOn installFrontend inputs.dir 'src/main/css' inputs.file '.stylelintrc.js' - script = 'run check:stylelint' + if (project.hasProperty('ci')) { + outputs.file "${buildDir}/stylelint.json" + script = 'run check:stylelint:ci' + } else { + script = 'run check:stylelint' + } group = 'verification' description = 'Check for Sass errors.' } @@ -142,4 +142,7 @@ sonarqube.properties { 'src/main/css/xtext/**', 'src/main/js/xtext/**', ] + property 'sonar.nodejs.executable', "${nodeDirectory}/bin/node" + property 'sonar.eslint.reportPaths', "${buildDir}/eslint.json" + property 'sonar.css.stylelint.reportPaths', "${buildDir}/stylelint.json" } diff --git a/language-web/package.json b/language-web/package.json index 2dfc6325..7a931d95 100644 --- a/language-web/package.json +++ b/language-web/package.json @@ -5,11 +5,12 @@ "main": "index.js", "scripts": { "assemble": "webpack --node-env production", - "stats": "webpack --node-env production --json > build/webpack/stats.json", "serve": "webpack serve --node-env development --hot", "check": "yarn run check:eslint && yarn run check:stylelint", "check:eslint": "eslint .", - "check:stylelint": "stylelint src/main/css/**/*.scss" + "check:eslint:ci": "eslint -c ./.eslintrc.ci.js -f json -o build/eslint.json .", + "check:stylelint": "stylelint src/main/css/**/*.scss", + "check:stylelint:ci": "stylelint -f json src/main/css/**/*.scss > build/stylelint.json" }, "repository": { "type": "git", @@ -33,9 +34,10 @@ "eslint-config-airbnb": "^18.2.1", "eslint-config-airbnb-typescript": "^14.0.0", "eslint-plugin-import": "^2.24.2", + "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-react": "^7.26.1", "eslint-plugin-react-hooks": "^4.2.0", - "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-sonarjs": "^0.10.0", "html-webpack-plugin": "^5.3.2", "image-webpack-loader": "^8.0.1", "magic-comments-loader": "^1.4.1", diff --git a/language-web/yarn.lock b/language-web/yarn.lock index 6caa3106..e87bc6ee 100644 --- a/language-web/yarn.lock +++ b/language-web/yarn.lock @@ -3135,6 +3135,11 @@ eslint-plugin-react@^7.26.1: semver "^6.3.0" string.prototype.matchall "^4.0.5" +eslint-plugin-sonarjs@^0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.10.0.tgz#2b520c6d0dbdecbea98cd82f5cb84fc5c3d2b954" + integrity sha512-FBRIBmWQh2UAfuLSnuYEfmle33jIup9hfkR0X8pkfjeCKNpHUG8qyZI63ahs3aw8CJrv47QJ9ccdK3ZxKH016A== + eslint-scope@5.1.1, eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" -- cgit v1.2.3-70-g09d2