Skip to content

Commit

Permalink
Update @typescript-eslint to ensure compatibility with TypeScript v3.9 (
Browse files Browse the repository at this point in the history
elastic#74091)

* bump @typescript-eslint deps

* update rules

* fix errors in pacakges

* fix src/

* fix x-pack

* fix test

* fix typings

* fix examples

* allow _ as prefix and suffix

* roll back prefix and suffix changes

* add eslint-plugin-eslint-comments

* report unused rules

* remove unused eslint comments from tests

* remove unused eslint comments 2nd pass

* remove unused eslint comments from src/

* remove unused comments in x-pack

* use no-script-url and no-unsanitized/property for ts files

* remove unused eslint comments

* eui/href-or-on-click removed when not complained

* no import/* rules for ts files

* cleanup

* remove the unused eslint-disable

* rollback unnecessary changes

* allow underscore prefix & sufix in type name

* update docs

* fix type error in enterprise search plugin mocks

* rename platform hack __coreProvider --> _coreProvider

* rollback space removal in src/core/public/legacy/legacy_service.test.ts

* fix naming convention in APM
# Conflicts:
#	src/legacy/ui/public/new_platform/new_platform.ts
#	x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor.tsx
  • Loading branch information
mshustov committed Aug 5, 2020
1 parent 4502447 commit dc0484b
Show file tree
Hide file tree
Showing 585 changed files with 670 additions and 780 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<b>Signature:</b>

```typescript
export interface ISyncStateRef<stateStorage extends IStateStorage = IStateStorage>
export interface ISyncStateRef<StateStorage extends IStateStorage = IStateStorage>
```

## Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';

export const CreateAlert = ({
http,
// eslint-disable-next-line @typescript-eslint/naming-convention
triggers_actions_ui,
charts,
uiSettings,
Expand Down
1 change: 1 addition & 0 deletions examples/alerting_example/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface AlertingExamplePublicStartDeps {
export class AlertingExamplePlugin implements Plugin<Setup, Start, AlertingExamplePublicSetupDeps> {
public setup(
core: CoreSetup<AlertingExamplePublicStartDeps, Start>,
// eslint-disable-next-line @typescript-eslint/naming-convention
{ alerts, triggers_actions_ui, developerExamples }: AlertingExamplePublicSetupDeps
) {
core.application.register({
Expand Down
1 change: 0 additions & 1 deletion kibana.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import * as LegacyKibanaServer from './src/legacy/server/kbn_server';
/**
* Re-export legacy types under a namespace.
*/
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Legacy {
export type KibanaConfig = LegacyKibanaServer.KibanaConfig;
export type Request = LegacyKibanaServer.Request;
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@
"@types/vinyl": "^2.0.4",
"@types/vinyl-fs": "^2.4.11",
"@types/zen-observable": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"angular-mocks": "^1.7.9",
"archiver": "^3.1.1",
"axe-core": "^3.4.1",
Expand All @@ -420,6 +420,7 @@
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-ban": "^1.4.0",
"eslint-plugin-cypress": "^2.8.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^23.10.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
Expand Down
9 changes: 5 additions & 4 deletions packages/eslint-config-kibana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
"author": "Spencer Alger <email@spalger.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/elastic/eslint-config-kibana/issues"
"url": "https://github.com/elastic/kibana/tree/master/packages/eslint-config-kibana"
},
"homepage": "https://github.com/elastic/eslint-config-kibana#readme",
"homepage": "https://github.com/elastic/kibana/tree/master/packages/eslint-config-kibana",
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"babel-eslint": "^10.0.3",
"eslint": "^6.8.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-ban": "^1.4.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^23.10.0",
"eslint-plugin-mocha": "^6.2.2",
Expand Down
91 changes: 84 additions & 7 deletions packages/eslint-config-kibana/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const PKG = require('../../package.json');

const eslintConfigPrettierTypescriptEslintRules = require('eslint-config-prettier/@typescript-eslint').rules;

// The current implementation excluded all the variables matching the regexp.
// We should remove it as soon as multiple underscores are supported by the linter.
// https://github.com/typescript-eslint/typescript-eslint/issues/1712
// Due to the same reason we have to duplicate the "filter" option for "default" and other "selectors".
const allowedNameRegexp = '^(UNSAFE_|_{1,3})|_{1,3}$';
module.exports = {
overrides: [
{
Expand All @@ -19,6 +24,7 @@ module.exports = {
'ban',
'import',
'prefer-object-spread',
'eslint-comments'
],

settings: {
Expand Down Expand Up @@ -88,16 +94,82 @@ module.exports = {
'React.StatelessComponent': {
message: 'Use FunctionComponent instead.',
fixWith: 'React.FunctionComponent'
}
},
// used in the codebase in the wild
'{}': false,
'object': false,
'Function': false,
}
}],
'camelcase': 'off',
'@typescript-eslint/camelcase': ['error', {
'properties': 'never',
'ignoreDestructuring': true,
'allow': ['^[A-Z0-9_]+$', '^UNSAFE_']
}],
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase'],
filter: {
regex: allowedNameRegexp,
match: false
}
},
{
selector: 'variable',
format: [
'camelCase',
'UPPER_CASE', // const SOMETHING = ...
'PascalCase', // React.FunctionComponent =
],
filter: {
regex: allowedNameRegexp,
match: false
}
},
{
selector: 'parameter',
format: [
'camelCase',
'PascalCase',
],
filter: {
regex: allowedNameRegexp,
match: false
}
},
{
selector: 'memberLike',
format: [
'camelCase',
'PascalCase',
'snake_case', // keys in elasticsearch requests / responses
'UPPER_CASE'
],
filter: {
regex: allowedNameRegexp,
match: false
}
},
{
selector: 'function',
format: [
'camelCase',
'PascalCase' // React.FunctionComponent =
],
filter: {
regex: allowedNameRegexp,
match: false
}
},
{
selector: 'typeLike',
format: ['PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'enum',
format: ['PascalCase', 'UPPER_CASE', 'camelCase'],
},
],
'@typescript-eslint/explicit-member-accessibility': ['error',
{
accessibility: 'off',
Expand Down Expand Up @@ -146,10 +218,12 @@ module.exports = {
'no-extend-native': 'error',
'no-eval': 'error',
'no-new-wrappers': 'error',
'no-script-url': 'error',
'no-shadow': 'error',
'no-throw-literal': 'error',
'no-undef-init': 'error',
'no-unsafe-finally': 'error',
'no-unsanitized/property': 'error',
'no-unused-expressions': 'error',
'no-unused-labels': 'error',
'no-var': 'error',
Expand All @@ -172,6 +246,9 @@ module.exports = {

],
'import/no-default-export': 'error',

'eslint-comments/no-unused-disable': 'error',
'eslint-comments/no-unused-enable': 'error'
},
eslintConfigPrettierTypescriptEslintRules
)
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-plugin-helpers/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export function babelRegister() {

try {
// add support for moved @babel/register source: https://github.com/elastic/kibana/pull/13973
require(resolve(plugin.kibanaRoot, 'src/setup_node_env/babel_register')); // eslint-disable-line import/no-dynamic-require
require(resolve(plugin.kibanaRoot, 'src/setup_node_env/babel_register'));
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
require(resolve(plugin.kibanaRoot, 'src/optimize/babel/register')); // eslint-disable-line import/no-dynamic-require
require(resolve(plugin.kibanaRoot, 'src/optimize/babel/register'));
} else {
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cluster/cluster_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,6 @@ export class ClusterManager {

onWatcherError = (err: any) => {
this.log.bad('failed to watch files!\n', err.stack);
process.exit(1); // eslint-disable-line no-process-exit
process.exit(1);
};
}
2 changes: 0 additions & 2 deletions src/core/server/config/config_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

/* eslint-disable max-classes-per-file */

import { BehaviorSubject, Observable } from 'rxjs';
import { first, take } from 'rxjs/operators';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

import { resolve } from 'path';
import supertest from 'supertest';
import { BehaviorSubject } from 'rxjs';
import { ByteSizeValue } from '@kbn/config-schema';
import pkg from '../../../../../package.json';

import { createHttpServer } from '../test_utils';
import { HttpService } from '../http_service';
Expand All @@ -30,8 +30,7 @@ import { IRouter, RouteRegistrar } from '../router';
import { configServiceMock } from '../../config/config_service.mock';
import { contextServiceMock } from '../../context/context_service.mock';

const pkgPath = resolve(__dirname, '../../../../../package.json');
const actualVersion = require(pkgPath).version;
const actualVersion = pkg.version;
const versionHeader = 'kbn-version';
const xsrfHeader = 'kbn-xsrf';
const nameHeader = 'kbn-name';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export class LegacyService implements CoreService {
// from being started multiple times in different processes.
// We only want one REPL.
if (this.coreContext.env.cliArgs.repl && process.env.kbnWorkerType === 'server') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../../cli/repl').startRepl(kbnServer);
}

Expand Down
2 changes: 0 additions & 2 deletions src/core/server/saved_objects/migrations/core/call_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import { IndexMapping } from '../../mappings';

/* eslint-disable @typescript-eslint/unified-signatures */
export interface CallCluster {
(path: 'bulk', opts: { body: object[] }): Promise<BulkResult>;
(path: 'count', opts: CountOpts): Promise<{ count: number; _shards: ShardsInfo }>;
Expand All @@ -49,7 +48,6 @@ export interface CallCluster {
error?: ErrorResponse;
}>;
}
/* eslint-enable @typescript-eslint/unified-signatures */

///////////////////////////////////////////////////////////////////
// callCluster argument type definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { registerBulkCreateRoute } from '../bulk_create';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

describe('POST /api/saved_objects/_bulk_create', () => {
let server: setupServerReturn['server'];
let httpSetup: setupServerReturn['httpSetup'];
let handlerContext: setupServerReturn['handlerContext'];
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];
let handlerContext: SetupServerReturn['handlerContext'];
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { registerBulkGetRoute } from '../bulk_get';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

describe('POST /api/saved_objects/_bulk_get', () => {
let server: setupServerReturn['server'];
let httpSetup: setupServerReturn['httpSetup'];
let handlerContext: setupServerReturn['handlerContext'];
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];
let handlerContext: SetupServerReturn['handlerContext'];
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { registerBulkUpdateRoute } from '../bulk_update';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

describe('PUT /api/saved_objects/_bulk_update', () => {
let server: setupServerReturn['server'];
let httpSetup: setupServerReturn['httpSetup'];
let handlerContext: setupServerReturn['handlerContext'];
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];
let handlerContext: SetupServerReturn['handlerContext'];
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { registerCreateRoute } from '../create';
import { savedObjectsClientMock } from '../../service/saved_objects_client.mock';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

describe('POST /api/saved_objects/{type}', () => {
let server: setupServerReturn['server'];
let httpSetup: setupServerReturn['httpSetup'];
let handlerContext: setupServerReturn['handlerContext'];
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];
let handlerContext: SetupServerReturn['handlerContext'];
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;

const clientResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { registerDeleteRoute } from '../delete';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

describe('DELETE /api/saved_objects/{type}/{id}', () => {
let server: setupServerReturn['server'];
let httpSetup: setupServerReturn['httpSetup'];
let handlerContext: setupServerReturn['handlerContext'];
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];
let handlerContext: SetupServerReturn['handlerContext'];
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { SavedObjectConfig } from '../../saved_objects_config';
import { registerExportRoute } from '../export';
import { setupServer, createExportableType } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
const exportSavedObjectsToStream = exportMock.exportSavedObjectsToStream as jest.Mock;
const allowedTypes = ['index-pattern', 'search'];
const config = {
Expand All @@ -38,9 +38,9 @@ const config = {
} as SavedObjectConfig;

describe('POST /api/saved_objects/_export', () => {
let server: setupServerReturn['server'];
let httpSetup: setupServerReturn['httpSetup'];
let handlerContext: setupServerReturn['handlerContext'];
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];
let handlerContext: SetupServerReturn['handlerContext'];

beforeEach(async () => {
({ server, httpSetup, handlerContext } = await setupServer());
Expand Down
Loading

0 comments on commit dc0484b

Please sign in to comment.