Upgrade eslint configuration and apply some rules on code

This commit is contained in:
ErickSkrauch 2019-05-15 18:56:13 +03:00
parent 77af422c03
commit 5547fd446b
21 changed files with 678 additions and 872 deletions

View File

@ -1,35 +1,35 @@
{ module.exports = {
"parser": "babel-eslint", parser: '@typescript-eslint/parser',
"plugins": [ parserOptions: {
"react" sourceType: 'module',
], ecmaVersion: 2018,
ecmaFeatures: {
"ecmaFeatures": { jsx: true,
"jsx": true, },
"modules": true, project: './tsconfig.json',
"classes": true,
"defaultParams": true,
"destructuring": true,
"spread": true,
"arrowFunctions": true,
"blockBindings": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"restParams": true,
"superInFunctions": true,
"templateStrings": true,
"experimentalObjectRestSpread": true
}, },
"env": { settings: {
react: {
version: 'detect',
},
},
env: {
"browser": true, "browser": true,
"commonjs": true, "commonjs": true,
"es6": true "es6": true
}, },
"extends": "eslint:recommended", plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
],
// @see: http://eslint.org/docs/rules/ // @see: http://eslint.org/docs/rules/
"rules": { "rules": {
@ -114,7 +114,7 @@
"no-path-concat": "warn", "no-path-concat": "warn",
// stylistic // stylistic
"array-bracket-spacing": "error", "array-bracket-spacing": "off", // disable because we want spaces on destructured arrays
"block-spacing": ["error", "never"], "block-spacing": ["error", "never"],
"brace-style": ["error", "1tbs", {"allowSingleLine": true}], "brace-style": ["error", "1tbs", {"allowSingleLine": true}],
"comma-spacing": "error", "comma-spacing": "error",
@ -180,13 +180,18 @@
"react/display-name": "warn", "react/display-name": "warn",
"react/forbid-prop-types": "warn", "react/forbid-prop-types": "warn",
"react/jsx-boolean-value": "warn", "react/jsx-boolean-value": "warn",
"react/jsx-closing-bracket-location": "warn", 'react/jsx-closing-bracket-location': ['warn', {
nonEmpty: 'line-aligned',
selfClosing: 'after-props',
}],
"react/jsx-curly-spacing": "warn", "react/jsx-curly-spacing": "warn",
"react/jsx-handler-names": ["warn", {"eventHandlerPrefix": "on", "eventHandlerPropPrefix": "on"}], "react/jsx-handler-names": ["warn", {"eventHandlerPrefix": "on", "eventHandlerPropPrefix": "on"}],
"react/jsx-indent-props": "warn", "react/jsx-indent-props": "warn",
"react/jsx-key": "warn", "react/jsx-key": "warn",
"react/jsx-max-props-per-line": ["warn", {"maximum": 3}], 'react/jsx-max-props-per-line': 'off',
"react/jsx-no-bind": "warn", "react/jsx-no-bind": ['error', {
allowArrowFunctions: true,
}],
"react/jsx-no-duplicate-props": "warn", "react/jsx-no-duplicate-props": "warn",
"react/jsx-no-literals": "off", "react/jsx-no-literals": "off",
"react/jsx-no-undef": "warn", "react/jsx-no-undef": "warn",
@ -205,9 +210,14 @@
"react/no-string-refs": "warn", "react/no-string-refs": "warn",
"react/no-unknown-property": "warn", "react/no-unknown-property": "warn",
"react/prefer-es6-class": "warn", "react/prefer-es6-class": "warn",
"react/prop-types": "warn", "react/prop-types": "off", // disable in favor of typescript
"react/react-in-jsx-scope": "off", "react/react-in-jsx-scope": "off",
"react/self-closing-comp": "warn", "react/self-closing-comp": "warn",
"react/sort-comp": ["warn", {"order": ["lifecycle", "render", "everything-else"]}] "react/sort-comp": ["warn", {"order": ["lifecycle", "render", "everything-else"]}],
}
} // TypeScript
'@typescript-eslint/array-type': ['error', 'generic'],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};

View File

@ -16,7 +16,7 @@
"homepage": "https://gitlab.com/elyby/email-renderer#README", "homepage": "https://gitlab.com/elyby/email-renderer#README",
"scripts": { "scripts": {
"start": "webpack-dev-server --mode=development --progress --colors", "start": "webpack-dev-server --mode=development --progress --colors",
"lint": "eslint ./src", "lint": "eslint",
"i18n:collect": "./scripts/i18n-collect/index.js", "i18n:collect": "./scripts/i18n-collect/index.js",
"i18n:pull": "node scripts/i18n-crowdin/index.js pull", "i18n:pull": "node scripts/i18n-crowdin/index.js pull",
"i18n:push": "node scripts/i18n-crowdin/index.js push", "i18n:push": "node scripts/i18n-crowdin/index.js push",
@ -37,11 +37,12 @@
"@types/react": "^16.8.17", "@types/react": "^16.8.17",
"@types/react-intl": "^2.3.17", "@types/react-intl": "^2.3.17",
"@types/webpack-env": "^1.13.9", "@types/webpack-env": "^1.13.9",
"babel-eslint": "^6.0.0", "@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"babel-loader": "^8.0.5", "babel-loader": "^8.0.5",
"babel-preset-react-hot": "^1.0.5", "babel-preset-react-hot": "^1.0.5",
"eslint": "^3.1.1", "eslint": "^5.16.0",
"eslint-plugin-react": "^6.0.0", "eslint-plugin-react": "^7.13.0",
"extended-translations-loader": "file:webpack-utils/extended-translations-loader", "extended-translations-loader": "file:webpack-utils/extended-translations-loader",
"file-loader": "^3.0.1", "file-loader": "^3.0.1",
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",

View File

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import React, { FunctionComponent } from 'react'; import React, { FunctionComponent } from 'react';
import { IntlProvider, addLocaleData } from 'react-intl'; import { IntlProvider, addLocaleData } from 'react-intl';

View File

@ -4,8 +4,7 @@ import styles from './styles';
import { Table } from 'components/table'; import { Table } from 'components/table';
const BaseLayout: FunctionComponent = ({ children }) => { const BaseLayout: FunctionComponent = ({ children }) => (
return (
<Table style={styles.body}> <Table style={styles.body}>
<tr> <tr>
<td> <td>
@ -19,7 +18,6 @@ const BaseLayout: FunctionComponent = ({ children }) => {
</td> </td>
</tr> </tr>
</Table> </Table>
); );
};
export default BaseLayout; export default BaseLayout;

View File

@ -1,19 +1,15 @@
import React, { FunctionComponent } from 'react'; import React, { FunctionComponent } from 'react';
const Html: FunctionComponent = ({ children }) => { const Html: FunctionComponent = ({ children }) => (
return (
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<meta httpEquiv="Content-Type" content="text/html; charset=UTF-8" /> <meta httpEquiv="Content-Type" content="text/html; charset=UTF-8" />
</head> </head>
<body style={{ <body style={{ margin: 0 }}>
margin: 0
}}>
{children} {children}
</body> </body>
</html> </html>
); );
};
export default Html; export default Html;

View File

@ -15,8 +15,7 @@ interface Props {
color?: Colors; color?: Colors;
} }
const Code: FunctionComponent<Props> = ({ code, link, label, color = 'green' }) => { const Code: FunctionComponent<Props> = ({ code, link, label, color = 'green' }) => (
return (
<div style={styles.codeWrapper}> <div style={styles.codeWrapper}>
<div> <div>
<a href={link}> <a href={link}>
@ -33,7 +32,6 @@ const Code: FunctionComponent<Props> = ({ code, link, label, color = 'green' })
<Input value={code} color={color} /> <Input value={code} color={color} />
</div> </div>
</div> </div>
); );
};
export default Code; export default Code;

View File

@ -2,12 +2,10 @@ import React, { FunctionComponent } from 'react';
import styles from './styles'; import styles from './styles';
const Content: FunctionComponent = ({ children }) => { const Content: FunctionComponent = ({ children }) => (
return (
<div style={styles.content}> <div style={styles.content}>
{children} {children}
</div> </div>
); );
};
export default Content; export default Content;

View File

@ -11,8 +11,7 @@ interface Props {
title: ReactElement; title: ReactElement;
} }
const Userbar: FunctionComponent<Props> = ({ username, title }) => { const Userbar: FunctionComponent<Props> = ({ username, title }) => (
return (
<Table style={styles.headerImage}> <Table style={styles.headerImage}>
<tr> <tr>
<td style={styles.headerTextContainer}> <td style={styles.headerTextContainer}>
@ -24,7 +23,6 @@ const Userbar: FunctionComponent<Props> = ({ username, title }) => {
</td> </td>
</tr> </tr>
</Table> </Table>
); );
};
export default Userbar; export default Userbar;

View File

@ -5,8 +5,7 @@ import { Table } from 'components/table';
import styles from './styles'; import styles from './styles';
import logoImage from './logo.png'; import logoImage from './logo.png';
const Userbar: FunctionComponent = () => { const Userbar: FunctionComponent = () => (
return (
<Table style={styles.userbar}> <Table style={styles.userbar}>
<tr> <tr>
<td style={styles.marginColumn} /> <td style={styles.marginColumn} />
@ -18,7 +17,6 @@ const Userbar: FunctionComponent = () => {
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
</Table> </Table>
); );
};
export default Userbar; export default Userbar;

View File

@ -6,8 +6,7 @@ interface Props {
style?: CSSProperties; style?: CSSProperties;
} }
const Table: FunctionComponent<Props> = ({ children, style }) => { const Table: FunctionComponent<Props> = ({ children, style }) => (
return (
<table cellPadding="0" cellSpacing="0" style={{ <table cellPadding="0" cellSpacing="0" style={{
...styles.table, ...styles.table,
...style ...style
@ -16,7 +15,6 @@ const Table: FunctionComponent<Props> = ({ children, style }) => {
{children} {children}
</tbody> </tbody>
</table> </table>
); );
};
export default Table; export default Table;

View File

@ -1,6 +1,6 @@
import React, { CSSProperties, FunctionComponent, ReactElement } from 'react'; import React, { CSSProperties, FunctionComponent, ReactElement } from 'react';
import { Colors, green } from 'components/ui/colors'; import { Colors } from 'components/ui/colors';
import styles from './styles'; import styles from './styles';
@ -10,9 +10,7 @@ interface Props {
color?: Colors; color?: Colors;
} }
const Button: FunctionComponent<Props> = ({ label, style, color = 'green' }) => { const Button: FunctionComponent<Props> = ({ label, style, color = 'green' }) => (
return (
<div style={{ <div style={{
...styles.button, ...styles.button,
...styles[color], ...styles[color],
@ -20,7 +18,6 @@ const Button: FunctionComponent<Props> = ({ label, style, color = 'green' }) =>
}}> }}>
{label} {label}
</div> </div>
); );
};
export default Button; export default Button;

View File

@ -7,7 +7,7 @@ function generateColor({ base }: Color): CSSProperties {
}; };
} }
type Styles = { interface Styles {
[key: string]: CSSProperties; [key: string]: CSSProperties;
} }

View File

@ -10,16 +10,14 @@ interface Props {
style?: CSSProperties; style?: CSSProperties;
} }
const Input: FunctionComponent<Props> = ({ value, style, color = 'green' }) => { const Input: FunctionComponent<Props> = ({ value, style, color = 'green' }) => (
return (
<div style={{ <div style={{
...styles.input, ...styles.input,
...styles[color], ...styles[color],
...style ...style,
}}> }}>
{value} {value}
</div> </div>
); );
};
export default Input; export default Input;

View File

@ -7,11 +7,10 @@ interface Props {
onChange: (item: string) => any; onChange: (item: string) => any;
} }
const List: FunctionComponent<Props> = ({ label, items, active, onChange = () => {} }) => { const List: FunctionComponent<Props> = ({ label, items, active, onChange = () => {} }) => (
return (
<div> <div>
{label}: {label}:
{items.map((item) => {items.map((item) => (
<a <a
href="#" href="#"
key={item} key={item}
@ -26,9 +25,8 @@ const List: FunctionComponent<Props> = ({ label, items, active, onChange = () =>
> >
{item} {item}
</a> </a>
)} ))}
</div> </div>
); );
};
export default List; export default List;

View File

@ -14,8 +14,7 @@ interface Props {
code: string; code: string;
} }
const ForgotPassword: FunctionComponent<Props> = ({ username, link, code }) => { const ForgotPassword: FunctionComponent<Props> = ({ username, link, code }) => (
return (
<div> <div>
<Userbar /> <Userbar />
@ -44,7 +43,6 @@ const ForgotPassword: FunctionComponent<Props> = ({ username, link, code }) => {
<Footer /> <Footer />
</div> </div>
); );
};
export default ForgotPassword; export default ForgotPassword;

View File

@ -18,8 +18,7 @@ interface Props {
code: string; code: string;
} }
const Register: FunctionComponent<Props> = ({ username, link, code }) => { const Register: FunctionComponent<Props> = ({ username, link, code }) => (
return (
<div> <div>
<Userbar /> <Userbar />
@ -116,7 +115,6 @@ const Register: FunctionComponent<Props> = ({ username, link, code }) => {
<Footer /> <Footer />
</div> </div>
); );
};
export default Register; export default Register;

View File

@ -6,7 +6,7 @@ declare module 'i18n/index.json' {
englishName: string; englishName: string;
progress: number; progress: number;
isReleased: boolean; isReleased: boolean;
}, };
}; };
export default content; export default content;
} }

View File

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// NOTE: we are requiring with require(), to enable dynamic dependencies // NOTE: we are requiring with require(), to enable dynamic dependencies
// depending on ENV, where App is running in. // depending on ENV, where App is running in.
// This allows us better support of hmr and reduces bundle size // This allows us better support of hmr and reduces bundle size

View File

@ -1,9 +1,9 @@
declare module "*.png" { declare module '*.png' {
const content: string; const content: string;
export default content; export default content;
} }
declare module "*.jpg" { declare module '*.jpg' {
const content: string; const content: string;
export default content; export default content;
} }

View File

@ -3,7 +3,7 @@ declare module '*.intl.json' {
[key: string]: { [key: string]: {
id: string; id: string;
defaultMessage: string; defaultMessage: string;
}, };
}; };
export default content; export default content;
} }

934
yarn.lock

File diff suppressed because it is too large Load Diff