Skip to content

Commit

Permalink
Added eslint plugin for enforcing and fixing import sort order and gr…
Browse files Browse the repository at this point in the history
…oupings. Fixed all source files that are nonconformant.
  • Loading branch information
msfterictraut committed Feb 15, 2020
1 parent f866c03 commit bc2c8d4
Show file tree
Hide file tree
Showing 41 changed files with 60 additions and 32 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
"@typescript-eslint/eslint-plugin",
"simple-import-sort"
],
"rules": {
"no-constant-condition": 0,
"no-inner-declarations": 0,
"no-undef": 0,
"simple-import-sort/sort": "error",
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/camelcase": 0,
Expand Down
7 changes: 3 additions & 4 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

import * as fs from 'fs';
import * as path from 'path';
import { commands, ExtensionContext, Position, Range, TextEditor, TextEditorEdit } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TextEdit,TransportKind } from 'vscode-languageclient';

import { ExtensionContext, commands, TextEditor, Range, Position, TextEditorEdit } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind,
TextEdit } from 'vscode-languageclient';
import { ProgressReporting } from './progress';
import { Commands } from '../../server/src/commands/commands';
import { ProgressReporting } from './progress';

export function activate(context: ExtensionContext) {
const bundlePath = context.asAbsolutePath(path.join('server', 'server.bundle.js'));
Expand Down
4 changes: 2 additions & 2 deletions client/src/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { Progress, ProgressLocation, window } from 'vscode';
import { Disposable, LanguageClient } from 'vscode-languageclient';

const AnalysisTimeoutInMs: number = 60000;
const AnalysisTimeoutInMs = 60000;

export class ProgressReporting implements Disposable {
private _progress: Progress<{ message?: string; increment?: number }> | undefined;
Expand All @@ -21,7 +21,7 @@ export class ProgressReporting implements Disposable {
constructor(languageClient: LanguageClient) {
languageClient.onReady().then(() => {
languageClient.onNotification('pyright/beginProgress', async () => {
let progressPromise = new Promise<void>(resolve => {
const progressPromise = new Promise<void>(resolve => {
this._resolveProgress = resolve;
});

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"@types/node": "^12.12.21",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"eslint": "^6.8.0",
"del-cli": "^3.0.0",
"eslint": "^6.8.0",
"eslint-plugin-simple-import-sort": "^5.0.1",
"typescript": "^3.7.3"
},
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion server/copyTypeshedFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This script helps build the command-line version of pyright
// by copying the typeshed-fallback directory to the dist directory.

var fsExtra = require('fs-extra');
const fsExtra = require('fs-extra');

// Clean the dist directory
fsExtra.emptyDirSync('../dist');
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { Commands } from '../commands/commands';
import { DiagnosticLevel } from '../common/configOptions';
import { assert, fail } from '../common/debug';
import { CreateTypeStubFileAction } from '../common/diagnostic';
import { getEmptyRange } from '../common/textRange';
import { DiagnosticRule } from '../common/diagnosticRules';
import { convertOffsetsToRange } from '../common/positionUtils';
import { PythonVersion } from '../common/pythonVersion';
import { getEmptyRange } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { ArgumentCategory, AssertNode, AssignmentExpressionNode, AssignmentNode,
AugmentedAssignmentNode, AwaitNode, BinaryOperationNode, BreakNode,
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { AssertNode, AssignmentExpressionNode, AssignmentNode, AugmentedAssignme
import { AnalyzerFileInfo } from './analyzerFileInfo';
import * as AnalyzerNodeInfo from './analyzerNodeInfo';
import { Declaration, DeclarationType } from './declaration';
import { isFinalVariableDeclaration } from './declarationUtils';
import { getTopLevelImports } from './importStatementUtils';
import * as ParseTreeUtils from './parseTreeUtils';
import { ParseTreeWalker } from './parseTreeWalker';
Expand All @@ -40,7 +41,6 @@ import { ClassType, combineTypes, FunctionType, isAnyOrUnknown, isNoneOrNever, i
import { containsUnknown, derivesFromClassRecursive, doForSubtypes,
getDeclaredGeneratorReturnType, getDeclaredGeneratorYieldType, getSymbolFromBaseClasses,
isNoReturnType, isProperty, specializeType, transformTypeObjectToClass } from './typeUtils';
import { isFinalVariableDeclaration } from './declarationUtils';

export class Checker extends ParseTreeWalker {
private readonly _moduleNode: ModuleNode;
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/importStatementUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* import statements in a python source file.
*/

import { Position } from '../common/textRange';
import { TextEditAction } from '../common/editAction';
import { convertOffsetToPosition } from '../common/positionUtils';
import { Position } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { ImportAsNode, ImportFromAsNode, ImportFromNode, ImportNode,
ModuleNameNode, ModuleNode, ParseNodeType } from '../parser/parseNodes';
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/parseTreeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { fail } from '../common/debug';
import { Position } from '../common/textRange';
import { convertPositionToOffset } from '../common/positionUtils';
import { Position } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { TextRangeCollection } from '../common/textRangeCollection';
import { ArgumentCategory, AssignmentExpressionNode, ClassNode, EvaluationScopeNode,
Expand Down
4 changes: 2 additions & 2 deletions server/src/analyzer/sourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
getDefaultDiagnosticSettings
} from '../common/configOptions';
import { ConsoleInterface, StandardConsole } from '../common/console';
import { Diagnostic, DiagnosticCategory } from '../common/diagnostic';
import { assert } from '../common/debug';
import { Diagnostic, DiagnosticCategory } from '../common/diagnostic';
import { DiagnosticSink, TextRangeDiagnosticSink } from '../common/diagnosticSink';
import { TextEditAction } from '../common/editAction';
import { getFileName, normalizeSlashes } from '../common/pathUtils';
import * as StringUtils from '../common/stringUtils';
import { TextRange, getEmptyRange, Position, DocumentRange } from '../common/textRange';
import { DocumentRange,getEmptyRange, Position, TextRange } from '../common/textRange';
import { TextRangeCollection } from '../common/textRangeCollection';
import { timingStats } from '../common/timing';
import { VirtualFileSystem } from '../common/vfs';
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { Commands } from '../commands/commands';
import { DiagnosticLevel } from '../common/configOptions';
import { assert, fail } from '../common/debug';
import { AddMissingOptionalToParamAction, Diagnostic, DiagnosticAddendum } from '../common/diagnostic';
import { getEmptyRange } from '../common/textRange';
import { DiagnosticRule } from '../common/diagnosticRules';
import { convertOffsetsToRange } from '../common/positionUtils';
import { PythonVersion } from '../common/pythonVersion';
import { getEmptyRange } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { ArgumentCategory, AssignmentNode, AugmentedAssignmentNode, BinaryOperationNode,
CallNode, ClassNode, ConstantNode, DecoratorNode, DictionaryNode, ExceptNode, ExpressionNode,
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

import { ParameterCategory } from '../parser/parseNodes';
import { ImportLookup } from './analyzerFileInfo';
import { DeclarationType } from './declaration';
import { Symbol, SymbolFlags, SymbolTable } from './symbol';
import { isTypedDictMemberAccessedThroughIndex } from './symbolUtils';
import { AnyType, ClassType, combineTypes, FunctionType, isAnyOrUnknown, isNoneOrNever,
isTypeSame, maxTypeRecursionCount, ModuleType, NeverType, ObjectType,
OverloadedFunctionType, SpecializedFunctionTypes, Type, TypeCategory,
TypeVarType, UnknownType } from './types';
import { DeclarationType } from './declaration';
import { TypeVarMap } from './typeVarMap';

export interface ClassMember {
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/typeVarMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* evaluator to "solve" for the type of each type variable.
*/

import { Type } from "./types";
import { assert } from "../common/debug";
import { Type } from "./types";

export class TypeVarMap {
private _typeMap: Map<string, Type>;
Expand Down
1 change: 1 addition & 0 deletions server/src/commands/commandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { ExecuteCommandParams, ResponseError } from 'vscode-languageserver';

import { LanguageServerBase } from '../languageServerBase';
import { Commands } from './commands';
import { CreateTypeStubCommand } from './createTypeStub';
Expand Down
1 change: 1 addition & 0 deletions server/src/commands/createTypeStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { ExecuteCommandParams } from 'vscode-languageserver';

import { AnalyzerService } from '../analyzer/service';
import { convertPathToUri } from '../common/pathUtils';
import { LanguageServerBase, WorkspaceServiceInstance } from '../languageServerBase';
Expand Down
1 change: 1 addition & 0 deletions server/src/commands/quickActionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { ExecuteCommandParams, TextEdit } from 'vscode-languageserver';

import { convertUriToPath } from '../common/pathUtils';
import { LanguageServerBase } from '../languageServerBase';
import { ServerCommand } from './commandController';
Expand Down
2 changes: 1 addition & 1 deletion server/src/common/diagnosticSink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Diagnostic, DiagnosticCategory } from './diagnostic';
import { convertOffsetsToRange } from './positionUtils';
import { TextRange, Range } from './textRange';
import { Range,TextRange } from './textRange';
import { TextRangeCollection } from './textRangeCollection';

// Represents a collection of diagnostics within a file.
Expand Down
1 change: 1 addition & 0 deletions server/src/common/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import * as path from 'path';
import Char from 'typescript-char';
import { URI } from 'vscode-uri';

import { some } from './collectionUtils';
import { compareValues, Comparison, GetCanonicalFileName, identity } from './core';
import * as debug from './debug';
Expand Down
2 changes: 1 addition & 1 deletion server/src/common/positionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* line/column positions.
*/

import { assert } from './debug';
import { Position, Range, TextRange } from './textRange';
import { TextRangeCollection } from './textRangeCollection';
import { assert } from './debug';

// Translates a file offset into a line/column pair.
export function convertOffsetToPosition(offset: number, lines: TextRangeCollection<TextRange>): Position {
Expand Down
1 change: 1 addition & 0 deletions server/src/common/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import leven from 'leven';

import { compareComparableValues, Comparison } from './core';

// Determines how closely a typed string matches a symbol
Expand Down
1 change: 1 addition & 0 deletions server/src/common/vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// * NOTE * except tests, this should be only file that import "fs"
import * as chokidar from 'chokidar';
import * as fs from 'fs';

import { ConsoleInterface, NullConsole } from './console';

export type Listener = (eventName: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string, stats?: Stats) => void;
Expand Down
5 changes: 3 additions & 2 deletions server/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Implements common language server functionality.
*/

import './common/extensions';

import {
CodeAction, CodeActionKind, CodeActionParams, Command,
ConfigurationItem, createConnection, Diagnostic, DiagnosticRelatedInformation,
Expand All @@ -15,10 +17,9 @@ import {
import { ImportResolver } from './analyzer/importResolver';
import { AnalyzerService } from './analyzer/service';
import { CommandLineOptions } from './common/commandLineOptions';
import { ConfigOptions } from './common/configOptions';
import { Diagnostic as AnalyzerDiagnostic, DiagnosticCategory } from './common/diagnostic';
import './common/extensions';
import { combinePaths, convertPathToUri, convertUriToPath, normalizePath } from './common/pathUtils';
import { ConfigOptions } from './common/configOptions';
import { Position } from './common/textRange';
import { createFromRealFileSystem, VirtualFileSystem } from './common/vfs';
import { CompletionItemData } from './languageService/completionProvider';
Expand Down
1 change: 1 addition & 0 deletions server/src/languageService/codeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { CodeAction, CodeActionKind, Command } from 'vscode-languageserver';

import { Commands } from '../commands/commands';
import { AddMissingOptionalToParamAction, CreateTypeStubFileAction } from '../common/diagnostic';
import { Range } from '../common/textRange';
Expand Down
6 changes: 3 additions & 3 deletions server/src/languageService/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import * as ParseTreeUtils from '../analyzer/parseTreeUtils';
import { Symbol, SymbolTable } from '../analyzer/symbol';
import * as SymbolNameUtils from '../analyzer/symbolNameUtils';
import { getLastTypedDeclaredForSymbol } from '../analyzer/symbolUtils';
import { TypeEvaluator, CallSignatureInfo } from '../analyzer/typeEvaluator';
import { FunctionType, TypeCategory, ClassType, Type } from '../analyzer/types';
import { CallSignatureInfo,TypeEvaluator } from '../analyzer/typeEvaluator';
import { ClassType, FunctionType, Type,TypeCategory } from '../analyzer/types';
import { doForSubtypes, getMembersForClass, getMembersForModule } from '../analyzer/typeUtils';
import { ConfigOptions } from '../common/configOptions';
import { comparePositions, Position } from '../common/textRange';
import { TextEditAction } from '../common/editAction';
import { combinePaths, getDirectoryPath, getFileName, stripFileExtension } from '../common/pathUtils';
import { convertOffsetToPosition, convertPositionToOffset } from '../common/positionUtils';
import * as StringUtils from '../common/stringUtils';
import { comparePositions, Position } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { ErrorExpressionCategory, ErrorNode, ExpressionNode,
FunctionNode, ImportFromNode, isExpressionNode, ModuleNameNode, NameNode,
Expand Down
2 changes: 1 addition & 1 deletion server/src/languageService/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import * as ParseTreeUtils from '../analyzer/parseTreeUtils';
import { TypeEvaluator } from '../analyzer/typeEvaluator';
import { Type, TypeCategory, UnknownType } from '../analyzer/types';
import { isProperty } from '../analyzer/typeUtils';
import { Position, Range } from '../common/textRange';
import { convertOffsetToPosition, convertPositionToOffset } from '../common/positionUtils';
import { Position, Range } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { NameNode, ParseNodeType } from '../parser/parseNodes';
import { ParseResults } from '../parser/parser';
Expand Down
2 changes: 1 addition & 1 deletion server/src/languageService/importSorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import { ImportType } from '../analyzer/importResult';
import * as ImportStatementUtils from '../analyzer/importStatementUtils';
import { Range } from '../common/textRange';
import { TextEditAction } from '../common/editAction';
import { convertOffsetToPosition } from '../common/positionUtils';
import { Range } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { ImportAsNode, ImportFromAsNode, ImportFromNode, ParseNodeType } from '../parser/parseNodes';
import { ParseResults } from '../parser/parser';
Expand Down
2 changes: 1 addition & 1 deletion server/src/languageService/referencesProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import * as DeclarationUtils from '../analyzer/declarationUtils';
import * as ParseTreeUtils from '../analyzer/parseTreeUtils';
import { ParseTreeWalker } from '../analyzer/parseTreeWalker';
import { TypeEvaluator } from '../analyzer/typeEvaluator';
import { Position, DocumentRange } from '../common/textRange';
import { convertOffsetToPosition, convertPositionToOffset } from '../common/positionUtils';
import { DocumentRange,Position } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { NameNode, ParseNode, ParseNodeType } from '../parser/parseNodes';
import { ParseResults } from '../parser/parser';
Expand Down
2 changes: 1 addition & 1 deletion server/src/languageService/signatureHelpProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { extractParameterDocumentation } from '../analyzer/docStringUtils';
import * as ParseTreeUtils from '../analyzer/parseTreeUtils';
import { TypeEvaluator } from '../analyzer/typeEvaluator';
import { FunctionType } from '../analyzer/types';
import { Position } from '../common/textRange';
import { convertPositionToOffset } from '../common/positionUtils';
import { Position } from '../common/textRange';
import { ParseResults } from '../parser/parser';

export interface ParamInfo {
Expand Down
1 change: 1 addition & 0 deletions server/src/parser/characterStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import Char from 'typescript-char';

import { isLineBreak, isWhiteSpace } from './characters';

export class CharacterStream {
Expand Down
1 change: 1 addition & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { isArray } from 'util';
import { CodeAction, CodeActionParams, Command, ExecuteCommandParams } from 'vscode-languageserver';

import { CommandController } from './commands/commandController';
import { convertUriToPath, getDirectoryPath, normalizeSlashes } from './common/pathUtils';
import { LanguageServerBase, ServerSettings, WorkspaceServiceInstance } from './languageServerBase';
Expand Down
1 change: 1 addition & 0 deletions server/src/tests/collectionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import * as assert from 'assert';

import * as utils from '../common/collectionUtils';
import { compareValues, isArray } from '../common/core';

Expand Down
2 changes: 1 addition & 1 deletion server/src/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AnalyzerService } from '../analyzer/service';
import { CommandLineOptions } from '../common/commandLineOptions';
import { ConfigOptions, ExecutionEnvironment } from '../common/configOptions';
import { NullConsole } from '../common/console';
import { combinePaths, normalizeSlashes, normalizePath } from '../common/pathUtils';
import { combinePaths, normalizePath,normalizeSlashes } from '../common/pathUtils';
import { createFromRealFileSystem } from '../common/vfs';

test('FindFilesWithConfigFile', () => {
Expand Down
1 change: 1 addition & 0 deletions server/src/tests/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import * as assert from 'assert';

import * as debug from '../common/debug';

test('DebugAssertTrue', () => {
Expand Down
3 changes: 2 additions & 1 deletion server/src/tests/filesystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*
* Test and Show how to use virtual file system
* Test and show how to use virtual file system
*/

import * as assert from 'assert';

import { combinePaths, normalizeSlashes } from '../common/pathUtils';
import * as host from './harness/host';
import * as factory from './harness/vfs/factory';
Expand Down
Loading

0 comments on commit bc2c8d4

Please sign in to comment.