Skip to content

Commit

Permalink
[DX] Prettier v2.2 (#83899)
Browse files Browse the repository at this point in the history
* update prettier with ts version support

* mute type-error

* run prettier on codebase

* fix examples

* fix errors after master merged
  • Loading branch information
mshustov authored Nov 23, 2020
1 parent df4f475 commit 95861a0
Show file tree
Hide file tree
Showing 172 changed files with 896 additions and 953 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ export class BookEmbeddableFactoryDefinition

private async unwrapMethod(savedObjectId: string): Promise<BookSavedObjectAttributes> {
const { savedObjectsClient } = await this.getStartServices();
const savedObject: SimpleSavedObject<BookSavedObjectAttributes> = await savedObjectsClient.get<
BookSavedObjectAttributes
>(this.type, savedObjectId);
const savedObject: SimpleSavedObject<BookSavedObjectAttributes> = await savedObjectsClient.get<BookSavedObjectAttributes>(
this.type,
savedObjectId
);
return { ...savedObject.attributes };
}

Expand Down Expand Up @@ -163,9 +164,9 @@ export class BookEmbeddableFactoryDefinition

private async getAttributeService() {
if (!this.attributeService) {
this.attributeService = (await this.getStartServices()).getAttributeService<
BookSavedObjectAttributes
>(this.type, {
this.attributeService = (
await this.getStartServices()
).getAttributeService<BookSavedObjectAttributes>(this.type, {
saveMethod: this.saveMethod.bind(this),
unwrapMethod: this.unwrapMethod.bind(this),
checkForDuplicateTitle: this.checkForDuplicateTitleMethod.bind(this),
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
"@types/pdfmake": "^0.1.15",
"@types/pegjs": "^0.10.1",
"@types/pngjs": "^3.4.0",
"@types/prettier": "^2.0.2",
"@types/prettier": "^2.1.5",
"@types/pretty-ms": "^5.0.0",
"@types/prop-types": "^15.7.3",
"@types/proper-lockfile": "^3.0.1",
Expand Down Expand Up @@ -626,7 +626,7 @@
"enzyme-adapter-utils": "^1.13.0",
"enzyme-to-json": "^3.4.4",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-prettier": "^6.15.0",
"eslint-import-resolver-node": "0.3.2",
"eslint-import-resolver-webpack": "0.11.1",
"eslint-module-utils": "2.5.0",
Expand Down Expand Up @@ -762,7 +762,7 @@
"postcss": "^7.0.32",
"postcss-loader": "^3.0.0",
"postcss-prefix-selector": "^1.7.2",
"prettier": "^2.1.1",
"prettier": "^2.2.0",
"pretty-ms": "5.0.0",
"proxyquire": "1.8.0",
"querystring": "^0.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function getSnapshotState(file: string, test: Test, updateSnapshots: boolean) {
path.join(dirname + `/__snapshots__/` + filename.replace(path.extname(filename), '.snap')),
{
updateSnapshot: updateSnapshots ? 'all' : 'new',
// @ts-expect-error
getPrettier: () => prettier,
getBabelTraverse: () => babelTraverse,
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/server/elasticsearch/elasticsearch_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ let coreContext: CoreContext;
const logger = loggingSystemMock.create();

let mockClusterClientInstance: ReturnType<typeof elasticsearchClientMock.createCustomClusterClient>;
let mockLegacyClusterClientInstance: ReturnType<typeof elasticsearchServiceMock.createLegacyCustomClusterClient>;
let mockLegacyClusterClientInstance: ReturnType<
typeof elasticsearchServiceMock.createLegacyCustomClusterClient
>;

beforeEach(() => {
env = Env.createDefault(REPO_ROOT, getEnvOptions());
Expand Down
4 changes: 1 addition & 3 deletions src/core/server/saved_objects/migrations/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import { SavedObjectMigrationContext } from './types';
import { SavedObjectsMigrationLogger } from './core';

export const createSavedObjectsMigrationLoggerMock = (): jest.Mocked<
SavedObjectsMigrationLogger
> => {
export const createSavedObjectsMigrationLoggerMock = (): jest.Mocked<SavedObjectsMigrationLogger> => {
const mock = {
debug: jest.fn(),
info: jest.fn(),
Expand Down
5 changes: 2 additions & 3 deletions src/core/server/saved_objects/saved_objects_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ describe('SavedObjectsService', () => {
await soService.setup(setupDeps);
soService.start(createStartDeps());
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(0);
((setupDeps.elasticsearch.esNodesCompatibility$ as any) as BehaviorSubject<
NodesVersionCompatibility
>).next({
((setupDeps.elasticsearch
.esNodesCompatibility$ as any) as BehaviorSubject<NodesVersionCompatibility>).next({
isCompatible: true,
incompatibleNodes: [],
warningNodes: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ describe('SavedObjectsRepository#createRepository', () => {
});

const migrator = mockKibanaMigrator.create({ types: typeRegistry.getAllTypes() });
const RepositoryConstructor = (SavedObjectsRepository as unknown) as jest.Mock<
SavedObjectsRepository
>;
const RepositoryConstructor = (SavedObjectsRepository as unknown) as jest.Mock<SavedObjectsRepository>;

beforeEach(() => {
RepositoryConstructor.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,20 +368,21 @@ export class LegacyCoreEditor implements CoreEditor {

// disable standard context based autocompletion.
// @ts-ignore
ace.define('ace/autocomplete/text_completer', ['require', 'exports', 'module'], function (
require: any,
exports: any
) {
exports.getCompletions = function (
innerEditor: any,
session: any,
pos: any,
prefix: any,
callback: any
) {
callback(null, []);
};
});
ace.define(
'ace/autocomplete/text_completer',
['require', 'exports', 'module'],
function (require: any, exports: any) {
exports.getCompletions = function (
innerEditor: any,
session: any,
pos: any,
prefix: any,
callback: any
) {
callback(null, []);
};
}
);

const langTools = ace.acequire('ace/ext/language_tools');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,90 +84,93 @@ describe('Integration', () => {
changeListener: function () {},
}; // mimic auto complete

senseEditor.autocomplete._test.getCompletions(senseEditor, null, cursor, '', function (
err,
terms
) {
if (testToRun.assertThrows) {
done();
return;
}
senseEditor.autocomplete._test.getCompletions(
senseEditor,
null,
cursor,
'',
function (err, terms) {
if (testToRun.assertThrows) {
done();
return;
}

if (err) {
throw err;
}
if (err) {
throw err;
}

if (testToRun.no_context) {
expect(!terms || terms.length === 0).toBeTruthy();
} else {
expect(terms).not.toBeNull();
expect(terms.length).toBeGreaterThan(0);
}
if (testToRun.no_context) {
expect(!terms || terms.length === 0).toBeTruthy();
} else {
expect(terms).not.toBeNull();
expect(terms.length).toBeGreaterThan(0);
}

if (!terms || terms.length === 0) {
done();
return;
}
if (!terms || terms.length === 0) {
done();
return;
}

if (testToRun.autoCompleteSet) {
const expectedTerms = _.map(testToRun.autoCompleteSet, function (t) {
if (typeof t !== 'object') {
t = { name: t };
}
return t;
});
if (terms.length !== expectedTerms.length) {
expect(_.map(terms, 'name')).toEqual(_.map(expectedTerms, 'name'));
} else {
const filteredActualTerms = _.map(terms, function (actualTerm, i) {
const expectedTerm = expectedTerms[i];
const filteredTerm = {};
_.each(expectedTerm, function (v, p) {
filteredTerm[p] = actualTerm[p];
});
return filteredTerm;
if (testToRun.autoCompleteSet) {
const expectedTerms = _.map(testToRun.autoCompleteSet, function (t) {
if (typeof t !== 'object') {
t = { name: t };
}
return t;
});
expect(filteredActualTerms).toEqual(expectedTerms);
if (terms.length !== expectedTerms.length) {
expect(_.map(terms, 'name')).toEqual(_.map(expectedTerms, 'name'));
} else {
const filteredActualTerms = _.map(terms, function (actualTerm, i) {
const expectedTerm = expectedTerms[i];
const filteredTerm = {};
_.each(expectedTerm, function (v, p) {
filteredTerm[p] = actualTerm[p];
});
return filteredTerm;
});
expect(filteredActualTerms).toEqual(expectedTerms);
}
}
}

const context = terms[0].context;
const {
cursor: { lineNumber, column },
} = testToRun;
senseEditor.autocomplete._test.addReplacementInfoToContext(
context,
{ lineNumber, column },
terms[0].value
);
const context = terms[0].context;
const {
cursor: { lineNumber, column },
} = testToRun;
senseEditor.autocomplete._test.addReplacementInfoToContext(
context,
{ lineNumber, column },
terms[0].value
);

function ac(prop, propTest) {
if (typeof testToRun[prop] !== 'undefined') {
if (propTest) {
propTest(context[prop], testToRun[prop], prop);
} else {
expect(context[prop]).toEqual(testToRun[prop]);
function ac(prop, propTest) {
if (typeof testToRun[prop] !== 'undefined') {
if (propTest) {
propTest(context[prop], testToRun[prop], prop);
} else {
expect(context[prop]).toEqual(testToRun[prop]);
}
}
}
}

function posCompare(actual, expected) {
expect(actual.lineNumber).toEqual(expected.lineNumber + lineOffset);
expect(actual.column).toEqual(expected.column);
}
function posCompare(actual, expected) {
expect(actual.lineNumber).toEqual(expected.lineNumber + lineOffset);
expect(actual.column).toEqual(expected.column);
}

function rangeCompare(actual, expected, name) {
posCompare(actual.start, expected.start, name + '.start');
posCompare(actual.end, expected.end, name + '.end');
}
function rangeCompare(actual, expected, name) {
posCompare(actual.start, expected.start, name + '.start');
posCompare(actual.end, expected.end, name + '.end');
}

ac('prefixToAdd');
ac('suffixToAdd');
ac('addTemplate');
ac('textBoxPosition', posCompare);
ac('rangeToReplace', rangeCompare);
done();
});
ac('prefixToAdd');
ac('suffixToAdd');
ac('addTemplate');
ac('textBoxPosition', posCompare);
ac('rangeToReplace', rangeCompare);
done();
}
);
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ export class DashboardPlugin
core: CoreSetup<StartDependencies, DashboardStart>,
{ share, uiActions, embeddable, home, urlForwarding, data, usageCollection }: SetupDependencies
): DashboardSetup {
this.dashboardFeatureFlagConfig = this.initializerContext.config.get<
DashboardFeatureFlagConfig
>();
this.dashboardFeatureFlagConfig = this.initializerContext.config.get<DashboardFeatureFlagConfig>();
const expandPanelAction = new ExpandPanelAction();
uiActions.registerAction(expandPanelAction);
uiActions.attachAction(CONTEXT_MENU_TRIGGER, expandPanelAction.id);
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data/common/search/aggs/param_types/agg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import { AggConfig, IAggConfig, AggConfigSerialized } from '../agg_config';
import { BaseParamType } from './base';

export class AggParamType<TAggConfig extends IAggConfig = IAggConfig> extends BaseParamType<
TAggConfig
> {
export class AggParamType<
TAggConfig extends IAggConfig = IAggConfig
> extends BaseParamType<TAggConfig> {
makeAgg: (agg: TAggConfig, state?: AggConfigSerialized) => TAggConfig;
allowedAggs: string[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ export function callClient(
fetchHandlers: FetchHandlers
) {
// Correlate the options with the request that they're associated with
const requestOptionEntries: Array<[
SearchRequest,
ISearchOptions
]> = searchRequests.map((request, i) => [request, requestsOptions[i]]);
const requestOptionEntries: Array<
[SearchRequest, ISearchOptions]
> = searchRequests.map((request, i) => [request, requestsOptions[i]]);
const requestOptionsMap = new Map<SearchRequest, ISearchOptions>(requestOptionEntries);
const requestResponseMap = new Map<SearchRequest, Promise<SearchResponse<any>>>();

Expand Down
4 changes: 1 addition & 3 deletions src/plugins/embeddable/common/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

import { EmbeddablePersistableStateService } from './types';

export const createEmbeddablePersistableStateServiceMock = (): jest.Mocked<
EmbeddablePersistableStateService
> => {
export const createEmbeddablePersistableStateServiceMock = (): jest.Mocked<EmbeddablePersistableStateService> => {
return {
inject: jest.fn((state, references) => state),
extract: jest.fn((state) => ({ state, references: [] })),
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/embeddable/public/lib/containers/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ export abstract class Container<

private createNewExplicitEmbeddableInput<
TEmbeddableInput extends EmbeddableInput = EmbeddableInput,
TEmbeddable extends IEmbeddable<TEmbeddableInput, EmbeddableOutput> = IEmbeddable<
TEmbeddableInput
>
TEmbeddable extends IEmbeddable<
TEmbeddableInput,
EmbeddableOutput
> = IEmbeddable<TEmbeddableInput>
>(
id: string,
factory: EmbeddableFactory<TEmbeddableInput, any, TEmbeddable>,
Expand Down
Loading

0 comments on commit 95861a0

Please sign in to comment.