mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[SIEM] Low impact linter rules to start with (#37137)
## Summary Low impact linter rules to help catch bugs for back-porting as well as moving into the future. We will slowly turn the warns into errors and fix the errors as we go along. This helps us avoid a "big bang" switch over approach to avoid back-port issues as we are porting bugs aggressively at the beginning. Added a custom pattern detection rule for determining if the UI is trying to import anything from the server backend since that would cause web-pack front to pull in backend code. Also forbid the use of NodeJS imports on the front end. Double checked that I was not duplicating rules from: * https://github.com/elastic/kibana/blob/master/packages/eslint-config-kibana/typescript.js * https://github.com/elastic/kibana/blob/master/packages/eslint-config-kibana/javascript.js ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. ~- [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~ ~- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~ ~- [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~ ~- [ ] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios~ ~- [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~ ### For maintainers ~- [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~ ~- [ ] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~
This commit is contained in:
parent
ca2a66dd26
commit
1cfad73abd
5 changed files with 189 additions and 5 deletions
179
.eslintrc.js
179
.eslintrc.js
|
@ -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'
|
||||
// '@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': [
|
||||
'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 }],
|
||||
'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',
|
||||
'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',
|
||||
'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',
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -57,6 +57,7 @@ type KeyUrlState = keyof UrlState;
|
|||
|
||||
interface UrlStateProps {
|
||||
indexPattern: StaticIndexPattern;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
mapToUrlState?: (value: any) => UrlState;
|
||||
onChange?: (urlState: UrlState, previousUrlState: UrlState) => void;
|
||||
onInitialize?: (urlState: UrlState) => void;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue