From 52f583fee762e35a88040d152e5a6a9cfe5ad05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 21 Dec 2018 14:23:32 +0100 Subject: [PATCH] @grafana/ui lib now contains one components, seperate lint & tsc steps --- jest.config.js | 4 +++- package.json | 3 ++- packages/grafana-ui/package.json | 14 +++++++++++- .../DeleteButton/DeleteButton.test.tsx | 9 ++++---- .../components/DeleteButton/DeleteButton.tsx | 8 +++---- packages/grafana-ui/tsconfig.json | 22 ++----------------- packages/grafana-ui/tslint.json | 3 +++ .../__snapshots__/TeamList.test.tsx.snap | 10 ++++----- .../__snapshots__/TeamMembers.test.tsx.snap | 20 ++++++++--------- scripts/grunt/default_task.js | 16 +++++++++++--- scripts/grunt/options/exec.js | 16 ++++++++++---- scripts/grunt/options/sasslint.js | 1 + scripts/grunt/options/tslint.js | 11 ---------- 13 files changed, 73 insertions(+), 64 deletions(-) create mode 100644 packages/grafana-ui/tslint.json delete mode 100644 scripts/grunt/options/tslint.js diff --git a/jest.config.js b/jest.config.js index cac634fbf10..e4d669edd8f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,9 @@ module.exports = { }, "moduleDirectories": ["node_modules", "public"], "roots": [ - "/public" + "/public/app", + "/public/test", + "packages" ], "testRegex": "(\\.|/)(test)\\.(jsx?|tsx?)$", "moduleFileExtensions": [ diff --git a/package.json b/package.json index 31e80e3b47d..0f0f7fefa83 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,8 @@ "watch": "webpack --progress --colors --watch --mode development --config scripts/webpack/webpack.dev.js", "build": "grunt build", "test": "grunt test", - "lint": "tslint -c tslint.json --project tsconfig.json", + "tslint": "tslint -c tslint.json --project tsconfig.json", + "typecheck": "tsc --noEmit", "jest": "jest --notify --watch", "api-tests": "jest --notify --watch --config=tests/api/jest.js", "precommit": "lint-staged && grunt precommit" diff --git a/packages/grafana-ui/package.json b/packages/grafana-ui/package.json index 1466e0de80a..39950d31d71 100644 --- a/packages/grafana-ui/package.json +++ b/packages/grafana-ui/package.json @@ -4,11 +4,23 @@ "description": "", "main": "src/index.ts", "scripts": { - "test": "tsc --noEmit" + "tslint": "tslint -c tslint.json --project tsconfig.json", + "typecheck": "tsc --noEmit" }, "author": "", "license": "ISC", + "dependencies": { + "react": "^16.6.3", + "react-dom": "^16.6.3", + "react-popper": "^1.3.0", + "react-highlight-words": "0.11.0", + "@torkelo/react-select": "2.1.1", + "react-transition-group": "^2.2.1", + "react-virtualized": "^9.21.0" + }, "devDependencies": { + "@types/jest": "^23.3.2", + "@types/react": "^16.7.6", "typescript": "^3.2.2" } } diff --git a/packages/grafana-ui/src/components/DeleteButton/DeleteButton.test.tsx b/packages/grafana-ui/src/components/DeleteButton/DeleteButton.test.tsx index 12acadee18a..f6d5a676971 100644 --- a/packages/grafana-ui/src/components/DeleteButton/DeleteButton.test.tsx +++ b/packages/grafana-ui/src/components/DeleteButton/DeleteButton.test.tsx @@ -1,10 +1,10 @@ import React from 'react'; -import DeleteButton from './DeleteButton'; +import { DeleteButton } from './DeleteButton'; import { shallow } from 'enzyme'; describe('DeleteButton', () => { - let wrapper; - let deleted; + let wrapper: any; + let deleted: any; beforeAll(() => { deleted = false; @@ -12,7 +12,8 @@ describe('DeleteButton', () => { function deleteItem() { deleted = true; } - wrapper = shallow( deleteItem()} />); + + wrapper = shallow( deleteItem()} />); }); it('should show confirm delete when clicked', () => { diff --git a/packages/grafana-ui/src/components/DeleteButton/DeleteButton.tsx b/packages/grafana-ui/src/components/DeleteButton/DeleteButton.tsx index de2db07aa04..df65d156ab3 100644 --- a/packages/grafana-ui/src/components/DeleteButton/DeleteButton.tsx +++ b/packages/grafana-ui/src/components/DeleteButton/DeleteButton.tsx @@ -1,7 +1,7 @@ -import React, { PureComponent } from 'react'; +import React, { PureComponent, SyntheticEvent } from 'react'; interface Props { - onConfirm(); + onConfirm(): void; } interface State { @@ -13,7 +13,7 @@ export class DeleteButton extends PureComponent { showConfirm: false, }; - onClickDelete = event => { + onClickDelete = (event: SyntheticEvent) => { if (event) { event.preventDefault(); } @@ -23,7 +23,7 @@ export class DeleteButton extends PureComponent { }); }; - onClickCancel = event => { + onClickCancel = (event: SyntheticEvent) => { if (event) { event.preventDefault(); } diff --git a/packages/grafana-ui/tsconfig.json b/packages/grafana-ui/tsconfig.json index f9e577c23d0..ed6009f1ebd 100644 --- a/packages/grafana-ui/tsconfig.json +++ b/packages/grafana-ui/tsconfig.json @@ -1,4 +1,5 @@ { + "extends": "../../tsconfig.json", "include": [ "src/**/*.ts", "src/**/*.tsx" @@ -6,30 +7,11 @@ "exclude": [ "dist" ], - "scripts": { - "build": "tsc" - }, "compilerOptions": { - "moduleResolution": "node", - "target": "es5", - "lib": ["es6", "dom"], - "jsx": "react", + "rootDir": ".", "module": "esnext", "outDir": "dist", - "declaration": false, - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "importHelpers": true, - "noEmitHelpers": true, - "removeComments": false, - "inlineSourceMap": false, - "sourceMap": true, - "noEmitOnError": false, - "emitDecoratorMetadata": false, - "experimentalDecorators": true, "declaration": true, - "declarationDir": "./dist/types", "noImplicitAny": true, "strictNullChecks": true } diff --git a/packages/grafana-ui/tslint.json b/packages/grafana-ui/tslint.json new file mode 100644 index 00000000000..0946f20963a --- /dev/null +++ b/packages/grafana-ui/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tslint.json" +} diff --git a/public/app/features/teams/__snapshots__/TeamList.test.tsx.snap b/public/app/features/teams/__snapshots__/TeamList.test.tsx.snap index 73f081d496a..ae94691df0e 100644 --- a/public/app/features/teams/__snapshots__/TeamList.test.tsx.snap +++ b/public/app/features/teams/__snapshots__/TeamList.test.tsx.snap @@ -124,7 +124,7 @@ exports[`Render should render teams table 1`] = ` className="text-right" > @@ -174,7 +174,7 @@ exports[`Render should render teams table 1`] = ` className="text-right" > @@ -224,7 +224,7 @@ exports[`Render should render teams table 1`] = ` className="text-right" > @@ -274,7 +274,7 @@ exports[`Render should render teams table 1`] = ` className="text-right" > @@ -324,7 +324,7 @@ exports[`Render should render teams table 1`] = ` className="text-right" > diff --git a/public/app/features/teams/__snapshots__/TeamMembers.test.tsx.snap b/public/app/features/teams/__snapshots__/TeamMembers.test.tsx.snap index d0a88bd97b0..5ebddb36d48 100644 --- a/public/app/features/teams/__snapshots__/TeamMembers.test.tsx.snap +++ b/public/app/features/teams/__snapshots__/TeamMembers.test.tsx.snap @@ -204,7 +204,7 @@ exports[`Render should render team members 1`] = ` className="text-right" > @@ -229,7 +229,7 @@ exports[`Render should render team members 1`] = ` className="text-right" > @@ -254,7 +254,7 @@ exports[`Render should render team members 1`] = ` className="text-right" > @@ -279,7 +279,7 @@ exports[`Render should render team members 1`] = ` className="text-right" > @@ -304,7 +304,7 @@ exports[`Render should render team members 1`] = ` className="text-right" > @@ -441,7 +441,7 @@ exports[`Render should render team members when sync enabled 1`] = ` className="text-right" > @@ -482,7 +482,7 @@ exports[`Render should render team members when sync enabled 1`] = ` className="text-right" > @@ -523,7 +523,7 @@ exports[`Render should render team members when sync enabled 1`] = ` className="text-right" > @@ -564,7 +564,7 @@ exports[`Render should render team members when sync enabled 1`] = ` className="text-right" > @@ -605,7 +605,7 @@ exports[`Render should render team members when sync enabled 1`] = ` className="text-right" > diff --git a/scripts/grunt/default_task.js b/scripts/grunt/default_task.js index 7b975aac977..1deb23eb220 100644 --- a/scripts/grunt/default_task.js +++ b/scripts/grunt/default_task.js @@ -15,10 +15,20 @@ module.exports = function (grunt) { 'no-only-tests' ]); + grunt.registerTask('tslint', [ + 'newer:exec:tslintPackages', + 'newer:exec:tslintRoot', + ]); + + grunt.registerTask('typecheck', [ + 'newer:exec:typecheckPackages', + 'newer:exec:typecheckRoot', + ]); + grunt.registerTask('precommit', [ - 'sasslint', - 'newer:exec:tslint', - 'newer:exec:tsc', + 'newer:sasslint', + 'typecheck', + 'tslint', 'no-only-tests' ]); diff --git a/scripts/grunt/options/exec.js b/scripts/grunt/options/exec.js index 3b60c5c3be6..27bfd7ae43d 100644 --- a/scripts/grunt/options/exec.js +++ b/scripts/grunt/options/exec.js @@ -2,12 +2,20 @@ module.exports = function (config, grunt) { 'use strict'; return { - tslint: { - command: 'node ./node_modules/tslint/lib/tslintCli.js -c tslint.json --project ./tsconfig.json', + tslintPackages: { + command: 'yarn workspaces run tslint', + src: ['packages/**/*.ts*'], + }, + tslintRoot: { + command: 'yarn run tslint', src: ['public/app/**/*.ts*'], }, - tsc: { - command: 'yarn tsc --noEmit', + typecheckPackages: { + command: 'yarn workspaces run typecheck', + src: ['packages/**/*.ts*'], + }, + typecheckRoot: { + command: 'yarn run typecheck', src: ['public/app/**/*.ts*'], }, jest: 'node ./node_modules/jest-cli/bin/jest.js --maxWorkers 2', diff --git a/scripts/grunt/options/sasslint.js b/scripts/grunt/options/sasslint.js index 8ba5ea3047f..9877f49a5a3 100644 --- a/scripts/grunt/options/sasslint.js +++ b/scripts/grunt/options/sasslint.js @@ -4,6 +4,7 @@ module.exports = function(config) { options: { configFile: 'public/sass/.sass-lint.yml', }, + // src: ['public/sass#<{(||)}>#*'], target: [ 'public/sass/*.scss', 'public/sass/components/*.scss', diff --git a/scripts/grunt/options/tslint.js b/scripts/grunt/options/tslint.js deleted file mode 100644 index d51c2062676..00000000000 --- a/scripts/grunt/options/tslint.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = function(config, grunt) { - 'use strict' - // dummy to avoid template compile error - return { - source: { - files: { - src: "" - } - } - }; -};