Skip to content

[eslint-plugin-blueprint] chore: run tests in CI, fix icon-components autofix #3938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:

compile:
docker: *docker-node-lts
resource_class: large
steps:
- checkout
- restore_cache: *restore-node-modules-cache
Expand All @@ -85,6 +86,7 @@ jobs:

dist:
docker: *docker-node-lts
resource_class: large
steps:
- checkout
- restore_cache: *restore-node-modules-cache
Expand All @@ -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:
Expand Down Expand Up @@ -182,6 +198,8 @@ workflows:
requires: [checkout-code]
- dist:
requires: [compile]
- test-jest:
requires: [compile]
- test-react-15:
requires: [compile]
- test-react-16:
Expand Down
28 changes: 26 additions & 2 deletions packages/eslint-plugin-blueprint/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
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,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
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;
6 changes: 4 additions & 2 deletions packages/eslint-plugin-blueprint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
11 changes: 6 additions & 5 deletions packages/eslint-plugin-blueprint/src/rules/icon-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ function create(context: RuleContext<MessageIds, Options>, node: TSESTree.JSXAtt
// no-op
} else if (valueNode.type === AST_NODE_TYPES.Literal && valueNode.value != null && option === OPTION_COMPONENT) {
// "tick" -> <TickIcon />
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,
});
Expand All @@ -81,7 +82,7 @@ function create(context: RuleContext<MessageIds, Options>, 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: {
Expand All @@ -96,7 +97,7 @@ function create(context: RuleContext<MessageIds, Options>, 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(/^-+/, "");
}

Expand Down
24 changes: 20 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==

[email protected]:
version "2.0.3"
Expand Down Expand Up @@ -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=

[email protected]:
version "8.2.2"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"
Expand Down