Merge pull request #1187 from scm-manager/feature/improve_eslint_config

improve eslint config
This commit is contained in:
eheimbuch
2020-06-16 11:57:50 +02:00
committed by GitHub
10 changed files with 1661 additions and 116 deletions

View File

@@ -8,7 +8,7 @@
"scripts": {
"build": "webpack --mode=production --config=scm-ui/ui-scripts/src/webpack.config.js",
"build:dev": "webpack --mode=development --config=scm-ui/ui-scripts/src/webpack.config.js",
"test": "lerna run --scope '@scm-manager/ui-*' test",
"test": "lerna run --scope '@scm-manager/ui-*' --scope '@scm-manager/eslint-config' test",
"typecheck": "lerna run --scope '@scm-manager/ui-*' typecheck",
"serve": "NODE_ENV=development webpack-dev-server --hot --mode=development --config=scm-ui/ui-scripts/src/webpack.config.js",
"deploy": "ui-scripts publish",

View File

@@ -2,16 +2,20 @@
"name": "@scm-manager/eslint-config",
"version": "2.0.0",
"description": "ESLint configuration for scm-manager and its plugins",
"main": "index.js",
"main": "src/index.js",
"author": "Sebastian Sdorra <s.sdorra@gmail.com>",
"license": "MIT",
"private": false,
"scripts": {
"test": "jest"
},
"prettier": "@scm-manager/prettier-config",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.5.1",
"eslint": "^7.2.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.4.0",
"eslint-config-react-app": "^5.0.2",
"eslint-plugin-flowtype": "^4.3.0",
@@ -21,6 +25,9 @@
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react-hooks": "^2.1.2"
},
"devDependencies": {
"jest": "^26.0.1"
},
"publishConfig": {
"access": "public"
}

View File

@@ -21,36 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
module.exports = {
extends: [
"react-app",
"plugin:prettier/recommended",
"plugin:flowtype/recommended"
],
rules: {
semi: ["error", "always"],
quotes: ["error", "double"],
"jsx-a11y/href-no-hash": [0],
"flowtype/no-types-missing-file-annotation": 2,
"no-console": "error"
},
overrides: [
{
files: ["*.ts", "*.tsx"],
parser: "@typescript-eslint/parser",
extends: [
"react-app",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended"
],
rules: {
semi: ["error", "always"],
quotes: ["error", "double"],
"jsx-a11y/href-no-hash": [0],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/ban-ts-ignore": "warn",
"no-console": "error"
}
}
]
};
import React, { FC } from "react";
import { Button } from "@scm-manager/ui-components";
const SpecialButton: FC = () => <Button color="primary">Special</Button>;
export default SpecialButton;

View File

@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React, { FC } from "react";
import Button from "@scm-manager/ui-components/src/buttons/Button";
const SpecialButton: FC = () => <Button color="primary">Special</Button>;
export default SpecialButton;

View File

@@ -0,0 +1,26 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var path = require('path')
console.log('we do not use path')

View File

@@ -0,0 +1,26 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const path = require('path');
console.log("from typscript");

View File

@@ -0,0 +1,25 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
console.log('from Sample.tsx')

View File

@@ -0,0 +1,94 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const rules = {
"prettier/prettier": "warn",
semi: ["error", "always"],
quotes: ["error", "double", "avoid-escape"],
"no-var": "error"
};
const nodeConfiguration = {
extends: ["airbnb-base", "plugin:prettier/recommended"],
rules: {
"no-console": "off",
...rules
}
};
const restrictImportConfig = {
patterns: ["@scm-manager/*/*"]
};
const typescriptConfiguration = {
parser: "@typescript-eslint/parser",
extends: ["react-app", "plugin:@typescript-eslint/recommended"],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/ban-ts-ignore": "warn",
"no-console": "error",
"jsx-a11y/href-no-hash": "off",
"no-restricted-imports": ["error", restrictImportConfig],
...rules
}
};
module.exports = {
overrides: [
{
files: ["*.test.js"],
env: {
node: true,
jest: true,
browser: false
},
...nodeConfiguration
},
{
files: ["*.js"],
env: {
node: true,
browser: false
},
...nodeConfiguration
},
{
files: ["*.test.ts", "*.test.tsx"],
env: {
node: true,
jest: true,
browser: false
},
...typescriptConfiguration
},
{
files: ["*.ts", "*.tsx"],
env: {
node: false,
browser: true
},
...typescriptConfiguration
}
]
};

View File

@@ -0,0 +1,79 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const { ESLint } = require("eslint");
const path = require("path");
const eslint = new ESLint();
const resource = path.join(__dirname, "__resources__");
const lint = async file => {
const results = await eslint.lintFiles([path.join(resource, file)]);
const { messages } = results[0];
const warnings = messages.filter(m => m.severity === 1).map(m => m.ruleId);
const errors = messages.filter(m => m.severity === 2).map(m => m.ruleId);
return {
errors,
warnings
};
};
const expectContains = (results, ...ids) => {
ids.forEach(id => expect(results).toContain(id));
};
describe("should lint different file types", () => {
it("should lint tsx files", async () => {
const { errors, warnings } = await lint("TypescriptWithJsx.tsx");
expectContains(errors, "no-console", "quotes", "semi");
expectContains(warnings, "prettier/prettier");
});
it("should lint js files", async () => {
const { errors, warnings } = await lint("Node.js");
expectContains(errors, "no-var", "quotes", "semi");
expectContains(warnings, "prettier/prettier");
});
it("should lint ts files", async () => {
const { errors, warnings } = await lint("Typescript.ts");
expectContains(errors, "no-console", "quotes");
expectContains(warnings, "prettier/prettier");
});
});
describe("lint @scm-manager imports", () => {
it("should return an error for source imports", async () => {
const { errors } = await lint("AvoidSourceImport.tsx");
expectContains(errors, "no-restricted-imports");
});
it("should return no error for package imports", async () => {
const { errors, warnings } = await lint("AllowRootImport.tsx");
expect(errors).toEqual([]);
expect(warnings).toEqual([]);
});
});

1444
yarn.lock

File diff suppressed because it is too large Load Diff