Skip to content

Commit

Permalink
Format ts code using Prettier (#9359)
Browse files Browse the repository at this point in the history
* Update config files and new entry
* Format ts using prettier
  • Loading branch information
DonJayamanne authored Jan 2, 2020
1 parent 43d30fd commit 2b6a8f2
Show file tree
Hide file tree
Showing 861 changed files with 32,981 additions and 31,630 deletions.
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"no-cond-assign": 0,
"no-unused-vars": 1,
"no-extra-semi": "warn",
"semi": "warn"
"semi": "warn",
"prettier/prettier": "error"
},
"extends": "eslint:recommended"
"extends": ["eslint:recommended", "prettier"],
"plugins": ["prettier"]
}
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"[typescript]": {
"editor.formatOnSave": true
},
"[javascript]": {
"editor.formatOnSave": true
},
"typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version
"tslint.enable": true,
"python.linting.enabled": false,
Expand All @@ -38,9 +41,12 @@
"typescript.preferences.quoteStyle": "single",
"javascript.preferences.quoteStyle": "single",
"typescriptHero.imports.stringQuoteStyle": "'",
"prettier.tslintIntegration": true,
"prettier.printWidth": 180,
"prettier.singleQuote": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.tslint": true
},
"python.jediEnabled": false,
"python.analysis.logLevel": "Trace",
"python.analysis.downloadChannel": "beta",
Expand Down
1 change: 1 addition & 0 deletions news/3 Code Health/2012.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use [prettier](https://prettier.io/) as the formatter for `TypeScript` code within the extension.
88 changes: 88 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@
"runtime": "node",
"variables": {
"pickProcess": "python.pickLocalProcess"
},
},
"configurationSnippets": [],
"configurationAttributes": {
"launch": {
Expand Down Expand Up @@ -2892,6 +2892,8 @@
"electron-download": "^4.1.1",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-prettier": "^3.1.2",
"event-stream": "3.3.4",
"expose-loader": "^0.7.5",
"extract-zip": "^1.6.7",
Expand Down Expand Up @@ -2927,6 +2929,7 @@
"node-has-native-dependencies": "^1.0.2",
"node-html-parser": "^1.1.13",
"nyc": "^14.1.1",
"prettier": "^1.19.1",
"raw-loader": "^0.5.1",
"react": "^16.5.2",
"react-data-grid": "^6.0.2-0",
Expand Down Expand Up @@ -2954,8 +2957,10 @@
"ts-mockito": "^2.3.1",
"ts-node": "^8.3.0",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"tslint-config-prettier": "^1.18.0",
"tslint-eslint-rules": "^5.1.0",
"tslint-microsoft-contrib": "^5.0.3",
"tslint-plugin-prettier": "^2.1.0",
"typed-react-markdown": "^0.1.0",
"typemoq": "^2.1.0",
"typescript": "^3.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/client/activation/aaTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IExtensionSingleActivationService } from './types';

@injectable()
export class AATesting implements IExtensionSingleActivationService {
constructor(@inject(IExperimentsManager) private experiments: IExperimentsManager) { }
constructor(@inject(IExperimentsManager) private experiments: IExperimentsManager) {}

public async activate(): Promise<void> {
this.experiments.sendTelemetryIfInExperiment(ValidateABTesting.experiment);
Expand Down
7 changes: 2 additions & 5 deletions src/client/activation/activationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
@inject(IApplicationDiagnostics) private readonly appDiagnostics: IApplicationDiagnostics,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IActiveResourceService) private readonly activeResourceService: IActiveResourceService
) { }
) {}

public dispose() {
while (this.disposables.length > 0) {
Expand All @@ -43,10 +43,7 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
public async activate(): Promise<void> {
await this.initialize();
// Activate all activation services together.
await Promise.all([
Promise.all(this.singleActivationServices.map(item => item.activate())),
this.activateWorkspace(this.activeResourceService.getActiveResource())
]);
await Promise.all([Promise.all(this.singleActivationServices.map(item => item.activate())), this.activateWorkspace(this.activeResourceService.getActiveResource())]);
await this.autoSelection.autoSelectInterpreter(undefined);
}
@traceDecorators.error('Failed to activate a workspace')
Expand Down
45 changes: 15 additions & 30 deletions src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import { IApplicationShell, ICommandManager, IWorkspaceService } from '../common
import { STANDARD_OUTPUT_CHANNEL } from '../common/constants';
import { LSControl, LSEnabled } from '../common/experimentGroups';
import { traceError } from '../common/logger';
import {
IConfigurationService,
IDisposableRegistry,
IExperimentsManager,
IOutputChannel,
IPersistentStateFactory,
IPythonSettings,
Resource
} from '../common/types';
import { IConfigurationService, IDisposableRegistry, IExperimentsManager, IOutputChannel, IPersistentStateFactory, IPythonSettings, Resource } from '../common/types';
import { swallowExceptions } from '../common/utils/decorators';
import { noop } from '../common/utils/misc';
import { IInterpreterService, PythonInterpreter } from '../interpreter/contracts';
Expand All @@ -28,12 +20,7 @@ import { sendTelemetryEvent } from '../telemetry';
import { EventName } from '../telemetry/constants';
import { Commands } from './languageServer/constants';
import { RefCountedLanguageServer } from './refCountedLanguageServer';
import {
IExtensionActivationService,
ILanguageServerActivator,
ILanguageServerCache,
LanguageServerType
} from './types';
import { IExtensionActivationService, ILanguageServerActivator, ILanguageServerCache, LanguageServerType } from './types';

const jediEnabledSetting: keyof IPythonSettings = 'jediEnabled';
const languageServerSetting: keyof IPythonSettings = 'languageServer';
Expand All @@ -56,17 +43,16 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
private readonly interpreterService: IInterpreterService;
private resource!: Resource;

constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer,
constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IPersistentStateFactory) private stateFactory: IPersistentStateFactory,
@inject(IExperimentsManager) private readonly abExperiments: IExperimentsManager) {
@inject(IExperimentsManager) private readonly abExperiments: IExperimentsManager
) {
this.workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
this.interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
this.output = this.serviceContainer.get<OutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
this.appShell = this.serviceContainer.get<IApplicationShell>(IApplicationShell);
this.lsNotSupportedDiagnosticService = this.serviceContainer.get<IDiagnosticsService>(
IDiagnosticsService,
LSNotSupportedDiagnosticServiceId
);
this.lsNotSupportedDiagnosticService = this.serviceContainer.get<IDiagnosticsService>(IDiagnosticsService, LSNotSupportedDiagnosticServiceId);
const commandManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
const disposables = serviceContainer.get<IDisposableRegistry>(IDisposableRegistry);
disposables.push(this);
Expand Down Expand Up @@ -154,7 +140,7 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
traceError('WorkspaceConfiguration.inspect returns `undefined` for setting `python.jediEnabled`');
return false;
}
return (settings.globalValue === undefined && settings.workspaceValue === undefined && settings.workspaceFolderValue === undefined);
return settings.globalValue === undefined && settings.workspaceValue === undefined && settings.workspaceFolderValue === undefined;
}

/**
Expand All @@ -172,7 +158,7 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
const configurationService = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
let enabled = configurationService.getSettings(this.resource).jediEnabled;
const languageServerType = configurationService.getSettings(this.resource).languageServer;
enabled = enabled || (languageServerType === LanguageServerType.Jedi);
enabled = enabled || languageServerType === LanguageServerType.Jedi;
this.sendTelemetryForChosenLanguageServer(enabled).ignoreErrors();
return enabled;
}
Expand Down Expand Up @@ -269,8 +255,10 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
const workspacesUris: (Uri | undefined)[] = this.workspaceService.hasWorkspaceFolders
? this.workspaceService.workspaceFolders!.map(workspace => workspace.uri)
: [undefined];
if (workspacesUris.findIndex(uri => event.affectsConfiguration(`python.${jediEnabledSetting}`, uri)) === -1 &&
workspacesUris.findIndex(uri => event.affectsConfiguration(`python.${languageServerSetting}`, uri)) === -1) {
if (
workspacesUris.findIndex(uri => event.affectsConfiguration(`python.${jediEnabledSetting}`, uri)) === -1 &&
workspacesUris.findIndex(uri => event.affectsConfiguration(`python.${languageServerSetting}`, uri)) === -1
) {
return;
}
const jedi = this.useJedi();
Expand All @@ -285,10 +273,7 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
}
}

const item = await this.appShell.showInformationMessage(
'Please reload the window switching between language engines.',
'Reload'
);
const item = await this.appShell.showInformationMessage('Please reload the window switching between language engines.', 'Reload');
if (item === 'Reload') {
this.serviceContainer.get<ICommandManager>(ICommandManager).executeCommand('workbench.action.reloadWindow');
}
Expand All @@ -302,6 +287,6 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv

private async onClearAnalysisCaches() {
const values = await Promise.all([...this.cache.values()]);
values.forEach(v => v.clearAnalysisCache ? v.clearAnalysisCache() : noop());
values.forEach(v => (v.clearAnalysisCache ? v.clearAnalysisCache() : noop()));
}
}
7 changes: 3 additions & 4 deletions src/client/activation/extensionSurvey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { ShowExtensionSurveyPrompt } from '../common/experimentGroups';
import '../common/extensions';
import { traceDecorators } from '../common/logger';
import { IPlatformService } from '../common/platform/types';
import {
IBrowserService, IExperimentsManager, IPersistentStateFactory, IRandom
} from '../common/types';
import { IBrowserService, IExperimentsManager, IPersistentStateFactory, IRandom } from '../common/types';
import { Common, ExtensionSurveyBanner, LanguageService } from '../common/utils/localize';
import { sendTelemetryEvent } from '../telemetry';
import { EventName } from '../telemetry/constants';
Expand All @@ -38,7 +36,8 @@ export class ExtensionSurveyPrompt implements IExtensionSingleActivationService
@inject(IApplicationEnvironment) private appEnvironment: IApplicationEnvironment,
@inject(IPlatformService) private platformService: IPlatformService,
@optional() private sampleSizePerOneHundredUsers: number = 10,
@optional() private waitTimeToShowSurvey: number = WAIT_TIME_TO_SHOW_SURVEY) { }
@optional() private waitTimeToShowSurvey: number = WAIT_TIME_TO_SHOW_SURVEY
) {}

public async activate(): Promise<void> {
if (!this.experiments.inExperiment(ShowExtensionSurveyPrompt.enabled)) {
Expand Down
Loading

0 comments on commit 2b6a8f2

Please sign in to comment.