mirror of
https://gitee.com/openharmony/third_party_typescript
synced 2025-02-20 12:02:53 +00:00
Enable @typescript-eslint/space-before-function-paren, @typescript-eslint/no-unused-expressions (#36569)
* use @typescript-eslint/no-unused-expressions instead of no-unused-expressions * enable @typescript-eslint/space-before-function-paren
This commit is contained in:
parent
7726464abd
commit
8c31700735
@ -26,6 +26,10 @@
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-this-alias": "error",
|
||||
|
||||
"no-unused-expressions": "off",
|
||||
"@typescript-eslint/no-unused-expressions": ["error", { "allowTernary": true }],
|
||||
|
||||
"@typescript-eslint/prefer-for-of": "error",
|
||||
"@typescript-eslint/prefer-function-type": "error",
|
||||
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||
@ -36,6 +40,13 @@
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": "error",
|
||||
|
||||
"space-before-function-paren": "off",
|
||||
"@typescript-eslint/space-before-function-paren": ["error", {
|
||||
"asyncArrow": "always",
|
||||
"anonymous": "always",
|
||||
"named": "never"
|
||||
}],
|
||||
|
||||
"@typescript-eslint/triple-slash-reference": "error",
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unified-signatures": "error",
|
||||
@ -97,7 +108,6 @@
|
||||
"no-trailing-spaces": "error",
|
||||
"no-undef-init": "error",
|
||||
"no-unsafe-finally": "error",
|
||||
"no-unused-expressions": ["error", { "allowTernary": true }],
|
||||
"no-unused-labels": "error",
|
||||
"no-var": "error",
|
||||
"object-shorthand": "error",
|
||||
|
14
package.json
14
package.json
@ -54,9 +54,9 @@
|
||||
"@types/through2": "latest",
|
||||
"@types/travis-fold": "latest",
|
||||
"@types/xml2js": "^0.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "2.3.2",
|
||||
"@typescript-eslint/experimental-utils": "2.3.2",
|
||||
"@typescript-eslint/parser": "2.3.2",
|
||||
"@typescript-eslint/eslint-plugin": "2.18.0",
|
||||
"@typescript-eslint/experimental-utils": "2.18.0",
|
||||
"@typescript-eslint/parser": "2.18.0",
|
||||
"async": "latest",
|
||||
"azure-devops-node-api": "^8.0.0",
|
||||
"browser-resolve": "^1.11.2",
|
||||
@ -65,10 +65,10 @@
|
||||
"chalk": "latest",
|
||||
"convert-source-map": "latest",
|
||||
"del": "5.1.0",
|
||||
"eslint": "6.5.1",
|
||||
"eslint-formatter-autolinkable-stylish": "1.0.3",
|
||||
"eslint-plugin-import": "2.18.2",
|
||||
"eslint-plugin-jsdoc": "15.9.9",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-formatter-autolinkable-stylish": "1.1.1",
|
||||
"eslint-plugin-import": "2.20.0",
|
||||
"eslint-plugin-jsdoc": "21.0.0",
|
||||
"eslint-plugin-no-null": "1.0.2",
|
||||
"fancy-log": "latest",
|
||||
"fs-extra": "^6.0.1",
|
||||
|
@ -23216,7 +23216,7 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
function getThisParameterFromNodeContext (node: Node) {
|
||||
function getThisParameterFromNodeContext(node: Node) {
|
||||
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false);
|
||||
return thisContainer && isFunctionLike(thisContainer) ? getThisParameter(thisContainer) : undefined;
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ namespace ts {
|
||||
const getDefaultLibLocation = memoize(() => getDirectoryPath(normalizePath(system.getExecutingFilePath())));
|
||||
let host: DirectoryStructureHost = system;
|
||||
// TODO: `host` is unused!
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
host;
|
||||
return {
|
||||
useCaseSensitiveFileNames: () => system.useCaseSensitiveFileNames,
|
||||
|
@ -54,7 +54,7 @@ namespace Utils {
|
||||
export function memoize<T extends ts.AnyFunction>(f: T, memoKey: (...anything: any[]) => string): T {
|
||||
const cache = ts.createMap<any>();
|
||||
|
||||
return <any>(function(this: any, ...args: any[]) {
|
||||
return <any>(function (this: any, ...args: any[]) {
|
||||
const key = memoKey(...args);
|
||||
if (cache.has(key)) {
|
||||
return cache.get(key);
|
||||
@ -395,4 +395,4 @@ namespace Utils {
|
||||
function isHarness(line: string) {
|
||||
return /[\\/]src[\\/]harness[\\/]|[\\/]run\.js/.test(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace ts.codefix {
|
||||
return Debug.assertDefined(getContainingClass(getTokenAtPosition(sourceFile, pos)), "There should be a containing class");
|
||||
}
|
||||
|
||||
function symbolPointsToNonPrivateMember (symbol: Symbol) {
|
||||
function symbolPointsToNonPrivateMember(symbol: Symbol) {
|
||||
return !symbol.valueDeclaration || !(getModifierFlags(symbol.valueDeclaration) & ModifierFlags.Private);
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ namespace ts.codefix {
|
||||
}
|
||||
}
|
||||
|
||||
function getHeritageClauseSymbolTable (classDeclaration: ClassLikeDeclaration, checker: TypeChecker): SymbolTable {
|
||||
function getHeritageClauseSymbolTable(classDeclaration: ClassLikeDeclaration, checker: TypeChecker): SymbolTable {
|
||||
const heritageClauseNode = getEffectiveBaseTypeNode(classDeclaration);
|
||||
if (!heritageClauseNode) return createSymbolTable();
|
||||
const heritageClauseType = checker.getTypeAtLocation(heritageClauseNode) as InterfaceType;
|
||||
|
@ -92,7 +92,7 @@ namespace ts.codefix {
|
||||
return flags;
|
||||
}
|
||||
|
||||
function getResolvedSourceFileFromImportDeclaration (sourceFile: SourceFile, context: CodeFixContextBase, importDeclaration: ImportDeclaration): SourceFile | undefined {
|
||||
function getResolvedSourceFileFromImportDeclaration(sourceFile: SourceFile, context: CodeFixContextBase, importDeclaration: ImportDeclaration): SourceFile | undefined {
|
||||
if (!importDeclaration || !isStringLiteralLike(importDeclaration.moduleSpecifier)) return undefined;
|
||||
|
||||
const resolvedModule = getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text);
|
||||
|
@ -47,12 +47,12 @@ namespace ts.codefix {
|
||||
},
|
||||
});
|
||||
|
||||
function getPropertyDeclaration (sourceFile: SourceFile, pos: number): PropertyDeclaration | undefined {
|
||||
function getPropertyDeclaration(sourceFile: SourceFile, pos: number): PropertyDeclaration | undefined {
|
||||
const token = getTokenAtPosition(sourceFile, pos);
|
||||
return isIdentifier(token) ? cast(token.parent, isPropertyDeclaration) : undefined;
|
||||
}
|
||||
|
||||
function getActionForAddMissingDefiniteAssignmentAssertion (context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
|
||||
function getActionForAddMissingDefiniteAssignmentAssertion(context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => addDefiniteAssignmentAssertion(t, context.sourceFile, propertyDeclaration));
|
||||
return createCodeFixAction(fixName, changes, [Diagnostics.Add_definite_assignment_assertion_to_property_0, propertyDeclaration.getText()], fixIdAddDefiniteAssignmentAssertions, Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
|
||||
}
|
||||
@ -70,7 +70,7 @@ namespace ts.codefix {
|
||||
changeTracker.replaceNode(propertyDeclarationSourceFile, propertyDeclaration, property);
|
||||
}
|
||||
|
||||
function getActionForAddMissingUndefinedType (context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
|
||||
function getActionForAddMissingUndefinedType(context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => addUndefinedType(t, context.sourceFile, propertyDeclaration));
|
||||
return createCodeFixAction(fixName, changes, [Diagnostics.Add_undefined_type_to_property_0, propertyDeclaration.name.getText()], fixIdAddUndefinedType, Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
|
||||
}
|
||||
@ -91,7 +91,7 @@ namespace ts.codefix {
|
||||
return createCodeFixAction(fixName, changes, [Diagnostics.Add_initializer_to_property_0, propertyDeclaration.name.getText()], fixIdAddInitializer, Diagnostics.Add_initializers_to_all_uninitialized_properties);
|
||||
}
|
||||
|
||||
function addInitializer (changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration, initializer: Expression): void {
|
||||
function addInitializer(changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration, initializer: Expression): void {
|
||||
const property = updateProperty(
|
||||
propertyDeclaration,
|
||||
propertyDeclaration.decorators,
|
||||
@ -108,7 +108,7 @@ namespace ts.codefix {
|
||||
return getDefaultValueFromType(checker, checker.getTypeFromTypeNode(propertyDeclaration.type!)); // TODO: GH#18217
|
||||
}
|
||||
|
||||
function getDefaultValueFromType (checker: TypeChecker, type: Type): Expression | undefined {
|
||||
function getDefaultValueFromType(checker: TypeChecker, type: Type): Expression | undefined {
|
||||
if (type.flags & TypeFlags.BooleanLiteral) {
|
||||
return (type === checker.getFalseType() || type === checker.getFalseType(/*fresh*/ true)) ? createFalse() : createTrue();
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
|
||||
return { renameFilename, renameLocation, edits };
|
||||
}
|
||||
|
||||
function isConvertibleName (name: DeclarationName): name is AcceptedNameType {
|
||||
function isConvertibleName(name: DeclarationName): name is AcceptedNameType {
|
||||
return isIdentifier(name) || isStringLiteral(name);
|
||||
}
|
||||
|
||||
@ -95,11 +95,11 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
|
||||
return isParameterPropertyDeclaration(node, node.parent) || isPropertyDeclaration(node) || isPropertyAssignment(node);
|
||||
}
|
||||
|
||||
function createPropertyName (name: string, originalName: AcceptedNameType) {
|
||||
function createPropertyName(name: string, originalName: AcceptedNameType) {
|
||||
return isIdentifier(originalName) ? createIdentifier(name) : createLiteral(name);
|
||||
}
|
||||
|
||||
function createAccessorAccessExpression (fieldName: AcceptedNameType, isStatic: boolean, container: ContainerDeclaration) {
|
||||
function createAccessorAccessExpression(fieldName: AcceptedNameType, isStatic: boolean, container: ContainerDeclaration) {
|
||||
const leftHead = isStatic ? (<ClassLikeDeclaration>container).name! : createThis(); // TODO: GH#18217
|
||||
return isIdentifier(fieldName) ? createPropertyAccess(leftHead, fieldName) : createElementAccess(leftHead, createLiteral(fieldName));
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace Harness {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const cls = this;
|
||||
describe(`${this.kind()} code samples`, function(this: Mocha.ISuiteCallbackContext) {
|
||||
describe(`${this.kind()} code samples`, function (this: Mocha.ISuiteCallbackContext) {
|
||||
this.timeout(600_000); // 10 minutes
|
||||
for (const test of testList) {
|
||||
cls.runTest(typeof test === "string" ? test : test.file);
|
||||
@ -41,7 +41,7 @@ namespace Harness {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const cls = this;
|
||||
const timeout = 600_000; // 10 minutes
|
||||
describe(directoryName, function(this: Mocha.ISuiteCallbackContext) {
|
||||
describe(directoryName, function (this: Mocha.ISuiteCallbackContext) {
|
||||
this.timeout(timeout);
|
||||
const cp: typeof import("child_process") = require("child_process");
|
||||
|
||||
@ -123,7 +123,7 @@ ${stripAbsoluteImportPaths(result.stderr.toString().replace(/\r\n/g, "\n"))}`;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const cls = this;
|
||||
describe(`${this.kind()} code samples`, function(this: Mocha.ISuiteCallbackContext) {
|
||||
describe(`${this.kind()} code samples`, function (this: Mocha.ISuiteCallbackContext) {
|
||||
this.timeout(cls.timeout); // 20 minutes
|
||||
before(() => {
|
||||
cls.exec("docker", ["build", ".", "-t", "typescript/typescript"], { cwd: IO.getWorkspaceRoot() }); // cached because workspace is hashed to determine cacheability
|
||||
|
@ -47,7 +47,7 @@ namespace RWC {
|
||||
caseSensitive = false;
|
||||
});
|
||||
|
||||
it("can compile", function(this: Mocha.ITestCallbackContext) {
|
||||
it("can compile", function (this: Mocha.ITestCallbackContext) {
|
||||
this.timeout(800_000); // Allow long timeouts for RWC compilations
|
||||
let opts!: ts.ParsedCommandLine;
|
||||
|
||||
@ -145,7 +145,7 @@ namespace RWC {
|
||||
});
|
||||
|
||||
|
||||
it("has the expected emitted code", function(this: Mocha.ITestCallbackContext) {
|
||||
it("has the expected emitted code", function (this: Mocha.ITestCallbackContext) {
|
||||
this.timeout(100_000); // Allow longer timeouts for RWC js verification
|
||||
Harness.Baseline.runMultifileBaseline(baseName, "", () => {
|
||||
return Harness.Compiler.iterateOutputs(compilerResult.js.values());
|
||||
|
@ -46,7 +46,7 @@ export function Component(x: Config): any;`
|
||||
it("should be able to create a language service which can respond to deinition requests without throwing", () => {
|
||||
const languageService = createLanguageService();
|
||||
const definitions = languageService.getDefinitionAtPosition("foo.ts", 160); // 160 is the latter `vueTemplateHtml` position
|
||||
expect(definitions).to.exist; // eslint-disable-line no-unused-expressions
|
||||
expect(definitions).to.exist; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
||||
});
|
||||
|
||||
it("getEmitOutput on language service has way to force dts emit", () => {
|
||||
|
@ -343,7 +343,7 @@ namespace ts.server {
|
||||
|
||||
session.send = Session.prototype.send;
|
||||
assert(session.send);
|
||||
expect(session.send(msg)).to.not.exist; // eslint-disable-line no-unused-expressions
|
||||
expect(session.send(msg)).to.not.exist; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
||||
expect(lastWrittenToHost).to.equal(resultMsg);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user