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

[ResponeOps][Alerting] Linting rules for the alerting plugin #185674

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
202 changes: 180 additions & 22 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,6 @@ module.exports = {
'x-pack/plugins/security_solution_serverless/common/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/timelines/public/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/timelines/common/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/cases/public/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/cases/common/**/*.{js,mjs,ts,tsx}',
'packages/kbn-cell-actions/**/*.{js,mjs,ts,tsx}',
],
rules: {
Expand All @@ -1130,7 +1128,6 @@ module.exports = {
files: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{ts,tsx}',
'x-pack/plugins/elastic_assistant/**/*.{ts,tsx}',
'x-pack/plugins/integration_assistant/**/*.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant-common/**/*.{ts,tsx}',
'x-pack/packages/kbn-langchain/**/*.{ts,tsx}',
Expand All @@ -1139,13 +1136,11 @@ module.exports = {
'x-pack/plugins/security_solution_ess/**/*.{ts,tsx}',
'x-pack/plugins/security_solution_serverless/**/*.{ts,tsx}',
'x-pack/plugins/timelines/**/*.{ts,tsx}',
'x-pack/plugins/cases/**/*.{ts,tsx}',
'packages/kbn-cell-actions/**/*.{js,mjs,ts,tsx}',
],
excludedFiles: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/elastic_assistant/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/integration_assistant/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant-common/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/packages/kbn-langchain/**/*.{test,mock,test_helper}.{ts,tsx}',
Expand All @@ -1154,7 +1149,6 @@ module.exports = {
'x-pack/plugins/security_solution_ess/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/security_solution_serverless/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/timelines/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/cases/**/*.{test,mock,test_helper}.{ts,tsx}',
'packages/kbn-cell-actions/**/*.{test,mock,test_helper}.{ts,tsx}',
],
rules: {
Expand All @@ -1166,7 +1160,6 @@ module.exports = {
files: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{ts,tsx}',
'x-pack/plugins/elastic_assistant/**/*.{ts,tsx}',
'x-pack/plugins/integration_assistant/**/*.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant-common/**/*.{ts,tsx}',
'x-pack/packages/kbn-langchain/**/*.{ts,tsx}',
Expand All @@ -1175,7 +1168,6 @@ module.exports = {
'x-pack/plugins/security_solution_ess/**/*.{ts,tsx}',
'x-pack/plugins/security_solution_serverless/**/*.{ts,tsx}',
'x-pack/plugins/timelines/**/*.{ts,tsx}',
'x-pack/plugins/cases/**/*.{ts,tsx}',
'packages/kbn-cell-actions/**/*.{ts,tsx}',
],
rules: {
Expand All @@ -1200,7 +1192,6 @@ module.exports = {
files: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/elastic_assistant/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/integration_assistant/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/kbn-elastic-assistant-common/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/kbn-langchain/**/*.{js,mjs,ts,tsx}',
Expand All @@ -1209,7 +1200,6 @@ module.exports = {
'x-pack/plugins/security_solution_ess/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/security_solution_serverless/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/timelines/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/cases/**/*.{js,mjs,ts,tsx}',
'packages/kbn-data-stream-adapter/**/*.{js,mjs,ts,tsx}',
'packages/kbn-cell-actions/**/*.{js,mjs,ts,tsx}',
],
Expand Down Expand Up @@ -1308,7 +1298,6 @@ module.exports = {
'x-pack/plugins/security_solution/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/security_solution_ess/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/security_solution_serverless/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/cases/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/kbn-data-stream-adapter/**/*.{js,mjs,ts,tsx}',
'packages/kbn-cell-actions/**/*.{js,mjs,ts,tsx}',
Expand All @@ -1319,13 +1308,6 @@ module.exports = {
},
],
},
{
files: ['x-pack/plugins/cases/public/**/*.{js,mjs,ts,tsx}'],
excludedFiles: ['x-pack/plugins/cases/**/*.{test,mock,test_helper}.{ts,tsx}'],
rules: {
'react/display-name': ['error', { ignoreTranspilerName: true }],
},
},

/**
* Lists overrides. These rules below are maintained and owned by
Expand Down Expand Up @@ -1533,13 +1515,11 @@ module.exports = {
},

/**
* Alerting Services overrides
* ResponseOps overrides
*/
{
// typescript for front and back end
files: [
'x-pack/plugins/{alerting,stack_alerts,actions,task_manager,event_log}/**/*.{ts,tsx}',
],
files: ['x-pack/plugins/{stack_alerts,actions,task_manager,event_log}/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
Expand All @@ -1552,6 +1532,184 @@ module.exports = {
},
},

{
// common and public files only
files: [
'x-pack/plugins/cases/common/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/cases/public/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/alerting/common/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/alerting/public/**/*.{js,mjs,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/*'],
},
],
},
},
{
// public files
files: [
'x-pack/plugins/cases/public/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/alerting/public/**/*.{js,mjs,ts,tsx}',
],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
plugins: ['react', '@typescript-eslint'],
rules: {
'import/no-nodejs-modules': 'error',
'react/boolean-prop-naming': 'error',
'react/button-has-type': 'error',
'react/display-name': 'error',
'react/forbid-dom-props': 'error',
'react/no-access-state-in-setstate': 'error',
'react/no-children-prop': 'error',
'react/no-danger-with-children': 'error',
'react/no-deprecated': 'error',
'react/no-did-mount-set-state': 'error',
'react/no-did-update-set-state': 'error',
'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',
'react/no-unescaped-entities': 'error',
'react/no-unsafe': 'error',
'react/no-unused-prop-types': 'error',
'react/no-unused-state': 'error',
'react/sort-default-props': 'error',
'react/void-dom-elements-no-children': 'error',
'react/jsx-no-comment-textnodes': 'error',
'react/jsx-no-literals': 'error',
'react/jsx-no-target-blank': 'error',
'react/jsx-fragments': 'error',
'react/jsx-no-useless-fragment': 'error',
'react/no-danger': 'error',
'react/no-array-index-key': 'error',
},
},
{
// typescript only for public, but excludes the test files.
files: [
'x-pack/plugins/cases/public/**/*.{ts,tsx}',
'x-pack/plugins/alerting/public/**/*.{ts,tsx}',
],
excludedFiles: [
'x-pack/plugins/cases/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/alerting/**/*.{test,mock,test_helper}.{ts,tsx}',
],
rules: {
'@typescript-eslint/no-non-null-assertion': 'error',
'react-perf/jsx-no-new-object-as-prop': 'error',
'react-perf/jsx-no-new-array-as-prop': 'error',
'react-perf/jsx-no-new-function-as-prop': 'error',
'react/jsx-no-bind': 'error',
'react/no-unstable-nested-components': 'error',
'react/jsx-no-leaked-render': 'error',
},
},
{
// front and back end
files: ['x-pack/plugins/cases/**/*.{ts,tsx}', 'x-pack/plugins/alerting/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/unified-signatures': 'error',
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react-router-dom',
importNames: ['Route'],
message: "import { Route } from '@kbn/kibana-react-plugin/public'",
},
],
},
],
},
},
{
// common, front and back end
files: [
'x-pack/plugins/cases/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/alerting/**/*.{js,mjs,ts,tsx}',
],
plugins: ['eslint-plugin-node', 'react'],
env: {
jest: true,
},
rules: {
'accessor-pairs': 'error',
'array-callback-return': 'error',
'no-array-constructor': 'error',
complexity: 'warn',
'node/no-deprecated-api': 'error',
'no-bitwise': 'error',
'no-continue': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'off',
'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-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',
'no-param-reassign': 'error',
'no-process-exit': 'error',
'no-prototype-builtins': 'error',
'no-return-await': 'error',
'no-self-compare': 'error',
'no-shadow-restricted-names': 'error',
'no-sparse-arrays': 'error',
'no-this-before-super': 'error',
// rely on typescript
'no-undef': 'off',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-useless-call': 'error',
'no-useless-catch': 'error',
'no-useless-concat': 'error',
'no-useless-computed-key': 'error',
'no-useless-rename': 'error',
'no-useless-return': 'error',
'one-var-declaration-per-line': 'error',
'prefer-object-spread': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'require-atomic-updates': 'error',
'symbol-description': 'error',
'vars-on-top': 'error',
'@typescript-eslint/no-duplicate-imports': ['error'],
'@typescript-eslint/consistent-type-imports': 'error',
},
},

/**
* Lens overrides
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-perf": "^3.3.1",
"eslint-plugin-testing-library": "^6.4.0",
"eslint-traverse": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ClusterPutComponentTemplateRequest } from '@elastic/elasticsearch/lib/api/types';
import type { ClusterPutComponentTemplateRequest } from '@elastic/elasticsearch/lib/api/types';
import { type FieldMap } from '@kbn/alerts-as-data-utils';
import { mappingFromFieldMap } from './mapping_from_field_map';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/common/bulk_edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { Rule } from './rule';
import type { Rule } from './rule';

export type BulkEditSkipReason = 'RULE_NOT_MODIFIED';

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/common/maintenance_window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/
import type { IUiSettingsClient, Logger, SavedObjectsClientContract } from '@kbn/core/server';
import { FilterStateStore } from '@kbn/es-query';
import { RRuleParams } from './rrule_type';
import type { FilterStateStore } from '@kbn/es-query';
import type { RRuleParams } from './rrule_type';

export enum MaintenanceWindowStatus {
Running = 'running',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/common/parse_duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function validateDurationSchema(duration: string) {
if (duration.match(DAYS_REGEX)) {
return;
}
return 'string is not a valid duration: ' + duration;
return `string is not a valid duration: ${duration}`;
}

function isSeconds(duration: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/

import type { TypeOf } from '@kbn/config-schema';
import { deleteParamsSchemaV1 } from '..';
import type { deleteParamsSchemaV1 } from '..';

export type DeleteBackfillRequestParams = TypeOf<typeof deleteParamsSchemaV1>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { TypeOf } from '@kbn/config-schema';
import { findQuerySchemaV1, findResponseSchemaV1 } from '..';
import type { findQuerySchemaV1, findResponseSchemaV1 } from '..';

export type FindBackfillRequestQuery = TypeOf<typeof findQuerySchemaV1>;
export type FindBackfillResponseBody = TypeOf<typeof findResponseSchemaV1>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { TypeOf } from '@kbn/config-schema';
import { getParamsSchemaV1, getResponseSchemaV1 } from '..';
import type { getParamsSchemaV1, getResponseSchemaV1 } from '..';

export type GetBackfillRequestParams = TypeOf<typeof getParamsSchemaV1>;
export type GetBackfillResponseBody = TypeOf<typeof getResponseSchemaV1>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { TypeOf } from '@kbn/config-schema';
import { scheduleBodySchemaV1, scheduleResponseSchemaV1 } from '..';
import type { scheduleBodySchemaV1, scheduleResponseSchemaV1 } from '..';

export type ScheduleBackfillRequestBody = TypeOf<typeof scheduleBodySchemaV1>;
export type ScheduleBackfillResponseBody = TypeOf<typeof scheduleResponseSchemaV1>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { TypeOf } from '@kbn/config-schema';
import { backfillResponseSchemaV1, errorResponseSchemaV1 } from '..';
import type { backfillResponseSchemaV1, errorResponseSchemaV1 } from '..';

export type BackfillResponse = TypeOf<typeof backfillResponseSchemaV1>;
export type ErrorResponse = TypeOf<typeof errorResponseSchemaV1>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { TypeOf } from '@kbn/config-schema';

import { healthFrameworkResponseBodySchemaV1, healthFrameworkResponseSchemaV1 } from '..';
import type { healthFrameworkResponseBodySchemaV1, healthFrameworkResponseSchemaV1 } from '..';

export type HealthFrameworkResponseBody = TypeOf<typeof healthFrameworkResponseBodySchemaV1>;
export type HealthFrameworkResponse = TypeOf<typeof healthFrameworkResponseSchemaV1>;
Loading