Skip to content
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

[SIEM] Low impact linter rules to start with #37137

Merged
merged 5 commits into from
May 28, 2019
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
179 changes: 177 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,185 @@ module.exports = {
* SIEM overrides
*/
{
files: ['x-pack/plugins/siem/**/*.ts'],
// front end typescript and javascript files only
files: ['x-pack/plugins/siem/public/**/*.{js,ts,tsx}'],
rules: {
'import/no-nodejs-modules': 'error',
'no-restricted-imports': [
'error',
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
},
],
},
},
{
// typescript only for front and back end
files: ['x-pack/plugins/siem/**/*.{ts,tsx}'],
rules: {
// This will be turned on after bug fixes are complete
// '@typescript-eslint/explicit-member-accessibility': 'warn',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'import/order': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
// This will be turned on after bug fixes are complete
// '@typescript-eslint/no-object-literal-type-assertion': 'warn',
'@typescript-eslint/unified-signatures': 'error',

// eventually we want this to be a warn and then an error since this is a recommended linter rule
// for now, keeping it commented out to avoid too much IDE noise until the other linter issues
// are fixed in the next release or two
// '@typescript-eslint/explicit-function-return-type': 'warn',

// these rules cannot be turned on and tested at the moment until this issue is resolved:
// https://github.com/prettier/prettier-eslint/issues/201
// '@typescript-eslint/await-thenable': 'error',
// '@typescript-eslint/no-non-null-assertion': 'error'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to this one! :)

// '@typescript-eslint/no-unnecessary-type-assertion': 'error',
// '@typescript-eslint/no-unused-vars': 'error',
// '@typescript-eslint/prefer-includes': 'error',
// '@typescript-eslint/prefer-string-starts-ends-with': 'error',
// '@typescript-eslint/promise-function-async': 'error',
// '@typescript-eslint/prefer-regexp-exec': 'error',
// '@typescript-eslint/promise-function-async': 'error',
// '@typescript-eslint/require-array-sort-compare': 'error',
// '@typescript-eslint/restrict-plus-operands': 'error',
// '@typescript-eslint/unbound-method': 'error',
},
},
{
// typescript and javascript for front and back end
files: ['x-pack/plugins/siem/**/*.{js,ts,tsx}'],
plugins: ['react'],
rules: {
'accessor-pairs': 'error',
'array-callback-return': 'error',
'no-array-constructor': 'error',
// This will be turned on after bug fixes are mostly completed
// 'arrow-body-style': ['warn', 'as-needed'],
complexity: 'warn',
// This will be turned on after bug fixes are mostly completed
// 'consistent-return': 'warn',
// This will be turned on after bug fixes are mostly completed
// 'func-style': ['warn', 'expression'],
// These will be turned on after bug fixes are mostly completed and we can
// run a fix-lint
/*
'import/order': [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited to get this back in as well. This is going to be a big change though, so I think holding off for now is 👍

'warn',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'always',
},
],
*/
'no-bitwise': 'error',
'no-continue': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
// This will be turned on after bug fixes are mostly completed
// 'no-duplicate-imports': 'warn',
'no-empty-character-class': 'error',
'no-empty-pattern': 'error',
'no-ex-assign': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-boolean-cast': 'error',
'no-extra-label': 'error',
'no-floating-decimal': 'error',
'no-func-assign': 'error',
'no-implicit-globals': 'error',
'no-implied-eval': 'error',
'no-invalid-regexp': 'error',
'no-inner-declarations': 'error',
'no-lone-blocks': 'error',
'no-multi-assign': 'error',
'no-misleading-character-class': 'error',
'no-new-symbol': 'error',
'no-obj-calls': 'error',
// This will be turned on after bug fixes are mostly complete
// 'no-param-reassign': 'warn',
'no-process-exit': 'error',
'no-prototype-builtins': 'error',
// This will be turned on after bug fixes are mostly complete
// 'no-return-await': 'warn',
'no-self-compare': 'error',
'no-shadow-restricted-names': 'error',
'no-sparse-arrays': 'error',
'no-this-before-super': 'error',
// This will be turned on after bug fixes are mostly complete
// 'no-undef': 'warn',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-useless-call': 'error',
// This will be turned on after bug fixes are mostly complete
// 'no-useless-catch': 'warn',
'no-useless-concat': 'error',
'no-useless-computed-key': 'error',
// This will be turned on after bug fixes are mostly complete
// 'no-useless-escape': 'warn',
'no-useless-rename': 'error',
// This will be turned on after bug fixes are mostly complete
// 'no-useless-return': 'warn',
// This will be turned on after bug fixers are mostly complete
// 'no-void': 'warn',
'one-var-declaration-per-line': 'error',
'prefer-object-spread': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
// This style will be turned on after most bugs are fixed
// 'prefer-template': 'warn',
// This style will be turned on after most bugs are fixed
// quotes: ['warn', 'single', { avoidEscape: true }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There've been plenty of PR comments for this one. ++ for this rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon for ones such as that one.

'react/boolean-prop-naming': 'error',
'react/button-has-type': 'error',
'react/forbid-dom-props': 'error',
// This will go from warn to error when this is fixed:
// https://github.com/elastic/ingest-dev/issues/468
'react/no-access-state-in-setstate': 'warn',
// This style will be turned on after most bugs are fixed
// 'react/no-children-prop': 'warn',
'react/no-danger-with-children': 'error',
'react/no-deprecated': 'error',
'react/no-did-mount-set-state': 'error',
// This will go from warn to error when this is fixed:
// https://github.com/elastic/ingest-dev/issues/468
'react/no-did-update-set-state': 'warn',
'react/no-direct-mutation-state': 'error',
'react/no-find-dom-node': 'error',
'react/no-redundant-should-component-update': 'error',
'react/no-render-return-value': 'error',
'react/no-typos': 'error',
'react/no-string-refs': 'error',
'react/no-this-in-sfc': 'error',
// This can go from warn to error once this is fixed
// https://github.com/elastic/ingest-dev/issues/467
'react/no-unescaped-entities': 'warn',
'react/no-unsafe': 'error',
'react/no-unused-prop-types': 'error',
'react/no-unused-state': 'error',
// will introduced after the other warns are fixed
// 'react/sort-comp': 'error',
'react/void-dom-elements-no-children': 'error',
'react/jsx-boolean-value': ['error', 'warn'],
// will introduced after the other warns are fixed
// 'react/jsx-no-bind': 'error',
Copy link
Member

@spong spong May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a strong argument for getting this rule on sooner than later from a perf standpoint. Should we open an issue for tracking to raise visibility? Turning it on showed 120 errors and it's pretty rampant around the DnD areas within the app.

'react/jsx-no-comment-textnodes': 'error',
// will be introduced to fix missing i18n keys
// 'react/jsx-no-literals': 'warn',
'react/jsx-no-target-blank': 'error',
'react/jsx-fragments': 'error',
'react/jsx-sort-default-props': 'error',
// might be introduced after the other warns are fixed
// 'react/jsx-sort-props': 'error',
Copy link
Member

@spong spong May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the existing patterns in the codebase, I think the team would be happy to have this enabled, albeit with the callbacksLast and reservedFirst options enabled as well.

'react/jsx-tag-spacing': 'error',
'require-atomic-updates': 'error',
'rest-spread-spacing': ['error', 'never'],
'symbol-description': 'error',
'template-curly-spacing': 'error',
'vars-on-top': 'error',
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ describe('Autocomplete', () => {
const wrapperAutocompleteField = wrapper.find(AutocompleteField);
wrapperAutocompleteField.setState({ selectedIndex: null });
const wrapperFixedEuiFieldSearch = wrapper.find(EuiFieldSearch);
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: FixedEuiFieldSearch fails to import
// TODO: FixedEuiFieldSearch fails to import
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(wrapperFixedEuiFieldSearch as any).props().onSearch();
expect(onSubmit).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import { NotePreviews } from './note_previews';
import { OPEN_TIMELINE_CLASS_NAME } from './helpers';

const getStateChildComponent = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
wrapper: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>
): React.Component<{}, {}, any> =>
): // eslint-disable-next-line @typescript-eslint/no-explicit-any
React.Component<{}, {}, any> =>
wrapper
.childAt(0)
.childAt(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import * as i18n from '../translations';
import { OpenTimelineModalButton } from '.';

const getStateChildComponent = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
wrapper: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>
): React.Component<{}, {}, any> =>
): // eslint-disable-next-line @typescript-eslint/no-explicit-any
React.Component<{}, {}, any> =>
wrapper
.childAt(0)
.childAt(0)
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/siem/public/components/url_state/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type KeyUrlState = keyof UrlState;

interface UrlStateProps {
indexPattern: StaticIndexPattern;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

mapToUrlState?: (value: any) => UrlState;
onChange?: (urlState: UrlState, previousUrlState: UrlState) => void;
onInitialize?: (urlState: UrlState) => void;
Expand Down Expand Up @@ -394,6 +395,7 @@ export const UrlStateContainer = connect(
// @ts-ignore
)(UrlStateComponents);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const decodeRisonUrlState = (value: string | undefined): RisonValue | any | undefined => {
try {
return value ? decode(value) : undefined;
Expand All @@ -405,6 +407,7 @@ export const decodeRisonUrlState = (value: string | undefined): RisonValue | any
}
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const encodeRisonUrlState = (state: any) => encode(state);

export const getQueryStringFromLocation = (location: Location) => location.search.substring(1);
Expand All @@ -414,6 +417,7 @@ export const getParamFromQueryString = (queryString: string, key: string): strin
return Array.isArray(queryParam) ? queryParam[0] : queryParam;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const replaceStateKeyInQueryString = <UrlState extends any>(
stateKey: string,
urlState: UrlState | undefined
Expand Down