From a711dc21b2129a951f81be0548dc14d09f1c3502 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 18 Mar 2020 15:09:48 +0100 Subject: [PATCH 1/5] cli: add and use app:lint + include default eslint config in cli --- .eslintrc.js | 35 +++------------------- packages/app/.eslintrc.js | 28 ------------------ packages/app/package.json | 5 +--- packages/cli/config/eslint.js | 42 +++++++++++++++++++++++++++ packages/cli/package.json | 1 + packages/cli/src/commands/app/lint.ts | 27 +++++++++++++++++ packages/cli/src/index.ts | 7 +++++ 7 files changed, 82 insertions(+), 63 deletions(-) delete mode 100644 packages/app/.eslintrc.js create mode 100644 packages/cli/config/eslint.js create mode 100644 packages/cli/src/commands/app/lint.ts diff --git a/.eslintrc.js b/.eslintrc.js index f228eb0e8a..a7cf9c3694 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,39 +16,12 @@ const copyrightTemplate = `/* `; +const base = require('@spotify-backstage/cli/config/eslint'); + module.exports = { - extends: [ - '@spotify/eslint-config-base', - '@spotify/eslint-config-react', - '@spotify/eslint-config-typescript', - 'prettier', - 'prettier/react', - 'prettier/@typescript-eslint', - 'plugin:jest/recommended', - ], - parser: '@typescript-eslint/parser', - plugins: ['notice'], - env: { - jest: true, - }, - parserOptions: { - ecmaVersion: 2018, - sourceType: 'module', - }, - settings: { - react: { - version: 'detect', - }, - }, - // Adding this to .eslintignore just doesn't even, let me know if you can make it work ._. - ignorePatterns: [ - '**/*_pb.js', - '**/*_pb.d.ts', - '**/dist/**', - '**/cjs/**', - '**/esm/**', - ], + ...base, rules: { + ...base.rules, 'notice/notice': [ 'error', { diff --git a/packages/app/.eslintrc.js b/packages/app/.eslintrc.js deleted file mode 100644 index 61650a3aa3..0000000000 --- a/packages/app/.eslintrc.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = { - parser: '@typescript-eslint/parser', // Specifies the ESLint parser - extends: [ - // Extend on the config used in `react-scripts` - require.resolve('react-scripts/node_modules/eslint-config-react-app'), - // If you want extra rules/extensions, it can be added here: - // 'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react - // 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin - ], - parserOptions: { - ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features - sourceType: 'module', // Allows for the use of imports - ecmaFeatures: { - jsx: true, // Allows for the parsing of JSX - }, - }, - rules: { - // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs - // e.g. "@typescript-eslint/explicit-function-return-type": "off", - }, - settings: { - react: { - version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use - }, - }, - // Adding this to .eslintignore just doesn't even, let me know if you can make it work ._. - ignorePatterns: ['**/*_pb.js', '**/*_pb.d.ts'], -}; diff --git a/packages/app/package.json b/packages/app/package.json index 5c1267bb58..ec950df39c 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -28,10 +28,7 @@ "start": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true backstage-cli watch-deps -- react-scripts start", "build": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true react-scripts build", "test": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true react-scripts test", - "lint": "cross-env EXTEND_ESLINT=true eslint ./src/**/*.{ts,tsx} --max-warnings=0 --format=codeframe" - }, - "eslintConfig": { - "extends": "react-app" + "lint": "backstage-cli app:lint" }, "browserslist": { "production": [ diff --git a/packages/cli/config/eslint.js b/packages/cli/config/eslint.js new file mode 100644 index 0000000000..e6e81d4de5 --- /dev/null +++ b/packages/cli/config/eslint.js @@ -0,0 +1,42 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports = { + extends: [ + '@spotify/eslint-config-base', + '@spotify/eslint-config-react', + '@spotify/eslint-config-typescript', + 'prettier', + 'prettier/react', + 'prettier/@typescript-eslint', + 'plugin:jest/recommended', + ], + parser: '@typescript-eslint/parser', + plugins: ['notice'], + env: { + jest: true, + }, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + }, + settings: { + react: { + version: 'detect', + }, + }, + ignorePatterns: ['**/dist/**', '**/build/**'], +}; diff --git a/packages/cli/package.json b/packages/cli/package.json index 5943d9c682..48aaa0dd73 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -50,6 +50,7 @@ }, "files": [ "templates", + "config", "bin", "dist" ], diff --git a/packages/cli/src/commands/app/lint.ts b/packages/cli/src/commands/app/lint.ts new file mode 100644 index 0000000000..1f1e4e6251 --- /dev/null +++ b/packages/cli/src/commands/app/lint.ts @@ -0,0 +1,27 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Command } from 'commander'; +import { run } from '../../helpers/run'; + +export default async (cmd: Command) => { + const args = ['lint']; + if (cmd.fix) { + args.push('--fix'); + } + + await run('web-scripts', args); +}; diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index ca465ec4b8..fc1369cde2 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -19,6 +19,7 @@ import chalk from 'chalk'; import fs from 'fs'; import createPluginCommand from './commands/createPlugin'; import watch from './commands/watch-deps'; +import appLint from './commands/app/lint'; import pluginBuild from './commands/plugin/build'; import pluginLint from './commands/plugin/lint'; import pluginServe from './commands/plugin/serve'; @@ -30,6 +31,12 @@ const main = (argv: string[]) => { program.name('backstage-cli').version(packageJson.version ?? '0.0.0'); + program + .command('app:lint') + .option('--fix', 'Attempt to automatically fix violations') + .description('Lint an app') + .action(actionHandler(appLint)); + program .command('create-plugin') .description('Creates a new plugin in the current repository') From 01771489d52b68f7cf3f174f4f987d310e45007c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 18 Mar 2020 16:27:08 +0100 Subject: [PATCH 2/5] cli: limit to 0 warnings and use codeframe format for lint tasks --- packages/cli/src/commands/app/lint.ts | 2 +- packages/cli/src/commands/plugin/lint.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/app/lint.ts b/packages/cli/src/commands/app/lint.ts index 1f1e4e6251..bacd66f1c7 100644 --- a/packages/cli/src/commands/app/lint.ts +++ b/packages/cli/src/commands/app/lint.ts @@ -18,7 +18,7 @@ import { Command } from 'commander'; import { run } from '../../helpers/run'; export default async (cmd: Command) => { - const args = ['lint']; + const args = ['lint', '--max-warnings=0', '--format=codeframe']; if (cmd.fix) { args.push('--fix'); } diff --git a/packages/cli/src/commands/plugin/lint.ts b/packages/cli/src/commands/plugin/lint.ts index 1f1e4e6251..bacd66f1c7 100644 --- a/packages/cli/src/commands/plugin/lint.ts +++ b/packages/cli/src/commands/plugin/lint.ts @@ -18,7 +18,7 @@ import { Command } from 'commander'; import { run } from '../../helpers/run'; export default async (cmd: Command) => { - const args = ['lint']; + const args = ['lint', '--max-warnings=0', '--format=codeframe']; if (cmd.fix) { args.push('--fix'); } From cedd53ec8aef49e613b49f5062237f3909096390 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 18 Mar 2020 16:58:07 +0100 Subject: [PATCH 3/5] app: fix lint issues --- packages/app/src/App.test.tsx | 16 ++++++++++++++++ packages/app/src/App.tsx | 16 ++++++++++++++++ packages/app/src/components/Root/Root.tsx | 23 ++++++++++++++++++++++- packages/app/src/components/Root/index.ts | 16 ++++++++++++++++ packages/app/src/index.tsx | 16 ++++++++++++++++ packages/app/src/plugins.ts | 16 ++++++++++++++++ packages/app/src/react-app-env.d.ts | 18 +++++++++++++++++- packages/app/src/setupTests.ts | 18 +++++++++++++++++- 8 files changed, 136 insertions(+), 3 deletions(-) diff --git a/packages/app/src/App.test.tsx b/packages/app/src/App.test.tsx index 0074416375..ace8f42f45 100644 --- a/packages/app/src/App.test.tsx +++ b/packages/app/src/App.test.tsx @@ -1,3 +1,19 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import React from 'react'; import { render } from '@testing-library/react'; import App from './App'; diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 484ae671ec..cb4c4470ba 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -1,3 +1,19 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { CssBaseline, makeStyles, ThemeProvider } from '@material-ui/core'; import { BackstageTheme, createApp } from '@spotify-backstage/core'; import React, { FC } from 'react'; diff --git a/packages/app/src/components/Root/Root.tsx b/packages/app/src/components/Root/Root.tsx index 07f4a1092f..af7759d86f 100644 --- a/packages/app/src/components/Root/Root.tsx +++ b/packages/app/src/components/Root/Root.tsx @@ -1,3 +1,21 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React, { FC, useContext } from 'react'; +import PropTypes from 'prop-types'; import { Link, makeStyles, Typography } from '@material-ui/core'; import HomeIcon from '@material-ui/icons/Home'; import { @@ -10,7 +28,6 @@ import { SidebarDivider, SidebarSpace, } from '@spotify-backstage/core'; -import React, { FC, useContext } from 'react'; const useSidebarLogoStyles = makeStyles({ root: { @@ -67,4 +84,8 @@ const Root: FC<{}> = ({ children }) => ( ); +Root.propTypes = { + children: PropTypes.node, +}; + export default Root; diff --git a/packages/app/src/components/Root/index.ts b/packages/app/src/components/Root/index.ts index 7ee9fa90d7..e997e09c18 100644 --- a/packages/app/src/components/Root/index.ts +++ b/packages/app/src/components/Root/index.ts @@ -1 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + export { default } from './Root'; diff --git a/packages/app/src/index.tsx b/packages/app/src/index.tsx index b597a44232..2ea8d3f1dd 100644 --- a/packages/app/src/index.tsx +++ b/packages/app/src/index.tsx @@ -1,3 +1,19 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; diff --git a/packages/app/src/plugins.ts b/packages/app/src/plugins.ts index 994c986533..486452b956 100644 --- a/packages/app/src/plugins.ts +++ b/packages/app/src/plugins.ts @@ -1,2 +1,18 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + export { default as HomePagePlugin } from '@spotify-backstage/plugin-home-page'; export { default as WelcomePlugin } from '@spotify-backstage/plugin-welcome'; diff --git a/packages/app/src/react-app-env.d.ts b/packages/app/src/react-app-env.d.ts index 6431bc5fc6..f4145f20db 100644 --- a/packages/app/src/react-app-env.d.ts +++ b/packages/app/src/react-app-env.d.ts @@ -1 +1,17 @@ -/// +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + diff --git a/packages/app/src/setupTests.ts b/packages/app/src/setupTests.ts index 74b1a275a0..e206a945cc 100644 --- a/packages/app/src/setupTests.ts +++ b/packages/app/src/setupTests.ts @@ -1,4 +1,20 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + // allows you to do things like: // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom From 0d9fd6d7ca6a6dc35f82e27a27d2a24528faa545 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 18 Mar 2020 17:11:57 +0100 Subject: [PATCH 4/5] app: remove copyright header in plugins list to avoid create-plugin mangling --- packages/app/src/plugins.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/packages/app/src/plugins.ts b/packages/app/src/plugins.ts index 486452b956..12bba3ac06 100644 --- a/packages/app/src/plugins.ts +++ b/packages/app/src/plugins.ts @@ -1,18 +1,3 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* eslint-disable notice/notice */ export { default as HomePagePlugin } from '@spotify-backstage/plugin-home-page'; export { default as WelcomePlugin } from '@spotify-backstage/plugin-welcome'; From d83267089c6197eb2513b819fe667fa3efaf9be5 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 18 Mar 2020 17:31:17 +0100 Subject: [PATCH 5/5] app: restored fixup'd comment line in setupTests --- packages/app/src/setupTests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/setupTests.ts b/packages/app/src/setupTests.ts index e206a945cc..17ff0c096d 100644 --- a/packages/app/src/setupTests.ts +++ b/packages/app/src/setupTests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ - +// jest-dom adds custom jest matchers for asserting on DOM nodes. // allows you to do things like: // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom