From a1fa4065396376123752d93334e961ff702bcbb1 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Wed, 22 Jan 2020 17:29:29 -0500 Subject: [PATCH] [eslint-plugin-blueprint] fix(icon-components): autofix (#3938) also run this package's tests in CI properly --- .circleci/config.yml | 18 ++++++++++++ .../eslint-plugin-blueprint/jest.config.js | 28 +++++++++++++++++-- packages/eslint-plugin-blueprint/package.json | 6 ++-- .../src/rules/icon-components.ts | 11 ++++---- yarn.lock | 24 +++++++++++++--- 5 files changed, 74 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e32e4c973f..664ac3dd93 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,6 +59,7 @@ jobs: compile: docker: *docker-node-lts + resource_class: large steps: - checkout - restore_cache: *restore-node-modules-cache @@ -85,6 +86,7 @@ jobs: dist: docker: *docker-node-lts + resource_class: large steps: - checkout - restore_cache: *restore-node-modules-cache @@ -94,6 +96,20 @@ jobs: root: '.' paths: [packages/*/lib, packages/*/dist] + test-jest: + docker: *docker-node-lts + environment: + JUNIT_REPORT_PATH: reports + # JEST_JUNIT_OUTPUT_DIR: "reports/junit/js-test-results.xml" + steps: + - checkout + - restore_cache: *restore-node-modules-cache + - attach_workspace: { at: '.' } + - run: mkdir ./reports + - run: yarn lerna run test:jest-ci + - store_test_results: { path: ./reports } + - store_artifacts: { path: ./reports } + test-react-16: &test-react docker: *docker-node-browsers environment: @@ -182,6 +198,8 @@ workflows: requires: [checkout-code] - dist: requires: [compile] + - test-jest: + requires: [compile] - test-react-15: requires: [compile] - test-react-16: diff --git a/packages/eslint-plugin-blueprint/jest.config.js b/packages/eslint-plugin-blueprint/jest.config.js index fe02f2a6ca..8be41213f3 100644 --- a/packages/eslint-plugin-blueprint/jest.config.js +++ b/packages/eslint-plugin-blueprint/jest.config.js @@ -1,7 +1,13 @@ -module.exports = { +/* + * Copyright 2020 Palantir Technologies, Inc. All rights reserved. + */ + +const path = require("path"); + +const config = { testEnvironment: 'node', transform: { - '^.+\\.tsx?$': 'ts-jest', + '^.+\\.tsx?$': 'ts-jest', }, testRegex: '__tests__\/.+\\.test\\.ts$', collectCoverage: false, @@ -9,3 +15,21 @@ module.exports = { moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], coverageReporters: ['text-summary', 'lcov'], }; + +if (process.env.JUNIT_REPORT_PATH) { + const outputDirectory = path.join( + __dirname, + '../..', + process.env.JUNIT_REPORT_PATH, + path.basename(__dirname) + ); + console.info(`Jest report will appear in ${outputDirectory}`); + config.reporters = [ + 'default',, + ['jest-junit', { + outputDirectory, + }] + ]; +} + +module.exports = config; diff --git a/packages/eslint-plugin-blueprint/package.json b/packages/eslint-plugin-blueprint/package.json index 4af71d55de..6722011e56 100644 --- a/packages/eslint-plugin-blueprint/package.json +++ b/packages/eslint-plugin-blueprint/package.json @@ -5,7 +5,8 @@ "main": "lib/index.js", "scripts": { "compile": "tsc -p src/", - "test": "jest" + "test": "jest", + "test:jest-ci": "jest --ci --runInBand" }, "dependencies": { "@typescript-eslint/eslint-plugin": "^2.11.0", @@ -23,6 +24,7 @@ "author": "Palantir Technologies", "license": "Apache-2.0", "devDependencies": { - "@types/dedent": "^0.7.0" + "@types/dedent": "^0.7.0", + "jest-junit": "^10.0.0" } } diff --git a/packages/eslint-plugin-blueprint/src/rules/icon-components.ts b/packages/eslint-plugin-blueprint/src/rules/icon-components.ts index 690e916a5a..a2663a43fd 100644 --- a/packages/eslint-plugin-blueprint/src/rules/icon-components.ts +++ b/packages/eslint-plugin-blueprint/src/rules/icon-components.ts @@ -66,13 +66,14 @@ function create(context: RuleContext, node: TSESTree.JSXAtt // no-op } else if (valueNode.type === AST_NODE_TYPES.Literal && valueNode.value != null && option === OPTION_COMPONENT) { // "tick" -> - const iconName = `<${pascalCase(sourceCode.getText(valueNode))}Icon />`; + const quotedIconName = sourceCode.getText(valueNode); + const iconTag = `<${pascalCase(quotedIconName.slice(1, quotedIconName.length - 1))}Icon />`; context.report({ data: { - component: iconName, + component: iconTag, }, - fix: fixer => fixer.replaceText(valueNode, `{${iconName}}`), + fix: fixer => fixer.replaceText(valueNode, `{${iconTag}}`), messageId: OPTION_COMPONENT, node, }); @@ -81,7 +82,7 @@ function create(context: RuleContext, node: TSESTree.JSXAtt const componentText = sourceCode.getText(valueNode.expression); const match = /<(\w+)Icon /.exec(componentText); if (match != null) { - const iconName = `"${dashCase(match[1])}"`; + const iconName = `"${kebabCase(match[1])}"`; context.report({ data: { @@ -96,7 +97,7 @@ function create(context: RuleContext, node: TSESTree.JSXAtt } /** "MultiWordPhrase" => "multi-word-phrase" */ -function dashCase(text: string) { +function kebabCase (text: string) { return text.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`).replace(/^-+/, ""); } diff --git a/yarn.lock b/yarn.lock index 2bbc8b445e..c32d814460 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6499,6 +6499,17 @@ jest-jasmine2@^24.9.0: pretty-format "^24.9.0" throat "^4.0.0" +jest-junit@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-10.0.0.tgz#c94b91c24920a327c9d2a075e897b2dba4af494b" + integrity sha512-dbOVRyxHprdSpwSAR9/YshLwmnwf+RSl5hf0kCGlhAcEeZY9aRqo4oNmaT0tLC16Zy9D0zekDjWkjHGjXlglaQ== + dependencies: + jest-validate "^24.9.0" + mkdirp "^0.5.1" + strip-ansi "^5.2.0" + uuid "^3.3.3" + xml "^1.0.1" + jest-leak-detector@^24.9.0: version "24.9.0" resolved "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-24.9.0.tgz#b665dea7c77100c5c4f7dfcb153b65cf07dcf96a" @@ -12200,10 +12211,10 @@ uuid@^2.0.1: resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" integrity sha1-Z+LoY3lyFVMN/zGOW/nc6/1Hsho= -uuid@^3.0.1, uuid@^3.1.0, uuid@^3.3.2: - version "3.3.3" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.3.tgz#4568f0216e78760ee1dbf3a4d2cf53e224112866" - integrity sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ== +uuid@^3.0.1, uuid@^3.1.0, uuid@^3.3.2, uuid@^3.3.3: + version "3.4.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" + integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== v8-compile-cache@2.0.3: version "2.0.3" @@ -12690,6 +12701,11 @@ xml-name-validator@^3.0.0: resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a" integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw== +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" + integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU= + xmlbuilder@8.2.2: version "8.2.2" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"