diff --git a/package-lock.json b/package-lock.json index 9be44e433..90a22ec20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "codelyzer", - "version": "4.3.0", + "version": "4.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -5434,9 +5434,9 @@ "dev": true }, "typescript": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.8.3.tgz", - "integrity": "sha512-K7g15Bb6Ra4lKf7Iq2l/I5/En+hLIHmxWZGq3D4DIRNFxMNV6j2SHSvDOqs2tGd4UvD/fJvrwopzQXjLrT7Itw==", + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz", + "integrity": "sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==", "dev": true }, "union-value": { diff --git a/package.json b/package.json index dc05a19d1..030035667 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "rxjs-compat": "^6.1.0", "ts-node": "^6.0.2", "tslint": "^5.10.0", - "typescript": "^2.8.0", + "typescript": "~2.7.0", "zone.js": "^0.8.26" }, "peerDependencies": { diff --git a/src/angular/metadataReader.ts b/src/angular/metadataReader.ts index ca53265ae..8b9418284 100644 --- a/src/angular/metadataReader.ts +++ b/src/angular/metadataReader.ts @@ -83,7 +83,7 @@ export class MetadataReader { inlineAnimations!.elements .filter(inlineAnimation => isSimpleTemplateString(inlineAnimation)) .map(inlineAnimation => ({ - animation: normalizeTransformed({ code: (inlineAnimation as ts.StringLiteralLike).text }), + animation: normalizeTransformed({ code: (inlineAnimation as ts.StringLiteral).text }), node: inlineAnimation as ts.Node })) ); @@ -115,7 +115,7 @@ export class MetadataReader { // Resolve Inline styles inlineStyles!.elements.filter(inlineStyle => isSimpleTemplateString(inlineStyle)).map(inlineStyle => ({ node: inlineStyle, - style: normalizeTransformed(Config.transformStyle((inlineStyle as ts.StringLiteralLike).text)) + style: normalizeTransformed(Config.transformStyle((inlineStyle as ts.StringLiteral).text)) })) ) .catch(() => diff --git a/src/angular/urlResolvers/abstractResolver.ts b/src/angular/urlResolvers/abstractResolver.ts index c0e37ec02..30f9860cf 100644 --- a/src/angular/urlResolvers/abstractResolver.ts +++ b/src/angular/urlResolvers/abstractResolver.ts @@ -17,12 +17,12 @@ export abstract class AbstractResolver { } const prop = arg.properties.find( - p => (p.name as ts.StringLiteralLike).text === 'templateUrl' && isSimpleTemplateString((p as ts.PropertyAssignment).initializer) + p => (p.name as ts.StringLiteral).text === 'templateUrl' && isSimpleTemplateString((p as ts.PropertyAssignment).initializer) ); // We know that it's has an initializer because it's either // a template string or a string literal. - return prop ? ((prop as ts.PropertyAssignment).initializer as ts.StringLiteralLike).text : undefined; + return prop ? ((prop as ts.PropertyAssignment).initializer as ts.StringLiteral).text : undefined; } protected getStyleUrls(decorator: ts.Decorator): string[] { @@ -39,7 +39,7 @@ export abstract class AbstractResolver { if (prop) { return ((prop as ts.PropertyAssignment).initializer as ts.ArrayLiteralExpression).elements .filter(isSimpleTemplateString) - .map(e => (e as ts.StringLiteralLike).text); + .map(e => (e as ts.StringLiteral).text); } return []; diff --git a/src/index.ts b/src/index.ts index e4b31362e..ee2a9115a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,7 @@ export { Rule as NoUnusedCssRule } from './noUnusedCssRule'; export { Rule as PipeImpureRule } from './pipeImpureRule'; export { Rule as PipeNamingRule } from './pipeNamingRule'; export { Rule as PreferOutputReadonlyRule } from './preferOutputReadonlyRule'; +export { Rule as PreferInlineDecorator } from './preferInlineDecoratorRule'; export { Rule as TemplateConditionalComplexityRule } from './templateConditionalComplexityRule'; export { Rule as TemplateCyclomaticComplexityRule } from './templateCyclomaticComplexityRule'; export { Rule as TemplatesNoNegatedAsync } from './templatesNoNegatedAsyncRule'; diff --git a/src/preferInlineDecoratorRule.ts b/src/preferInlineDecoratorRule.ts index 3e0172b7b..f33ad68a1 100644 --- a/src/preferInlineDecoratorRule.ts +++ b/src/preferInlineDecoratorRule.ts @@ -1,5 +1,6 @@ +import * as ts from 'typescript'; + import { IOptions, IRuleMetadata, Replacement, RuleFailure, Rules } from 'tslint/lib'; -import { isSameLine } from 'tsutils'; import { Decorator, Node, PropertyAccessExpression, SourceFile } from 'typescript'; import { NgWalker } from './angular/ngWalker'; import { getDecoratorName } from './util/utils'; @@ -102,3 +103,7 @@ export class PreferInlineDecoratorWalker extends NgWalker { this.addFailureAt(decoratorStartPos, property.getWidth(), getFailureMessage(), fix); } } + +function isSameLine(sourceFile: ts.SourceFile, pos1: number, pos2: number) { + return ts.getLineAndCharacterOfPosition(sourceFile, pos1).line === ts.getLineAndCharacterOfPosition(sourceFile, pos2).line; +} \ No newline at end of file diff --git a/src/selectorNameBase.ts b/src/selectorNameBase.ts index 3e0a8b2f5..0fe5bbad2 100644 --- a/src/selectorNameBase.ts +++ b/src/selectorNameBase.ts @@ -148,7 +148,7 @@ export class SelectorValidatorWalker extends Lint.RuleWalker { } private validateProperty(p: ts.PropertyAssignment): boolean { - return ts.isStringLiteralLike(p.initializer) && ts.isIdentifier(p.name) && p.name.text === 'selector'; + return p.initializer.kind === ts.SyntaxKind.StringLiteral && ts.isIdentifier(p.name) && p.name.text === 'selector'; } private extractMainSelector(expression: ts.StringLiteral): compiler.CssSelector[] { diff --git a/src/util/astQuery.ts b/src/util/astQuery.ts index d48418203..f00a954ac 100644 --- a/src/util/astQuery.ts +++ b/src/util/astQuery.ts @@ -29,13 +29,13 @@ export function getInitializer(p: ts.ObjectLiteralElement): Maybe -): Maybe { +): Maybe { const property = ps.find(p => isProperty(propertyName, p))!; return ( getInitializer(property) - // A little wrinkle to return Maybe - .fmap(expr => (expr && isSimpleTemplateString(expr) ? (expr as ts.StringLiteralLike) : undefined)) + // A little wrinkle to return Maybe + .fmap(expr => (expr && isSimpleTemplateString(expr) ? (expr as ts.StringLiteral) : undefined)) ); } diff --git a/src/util/ngQuery.ts b/src/util/ngQuery.ts index 14d9d78ac..d4a3f177e 100644 --- a/src/util/ngQuery.ts +++ b/src/util/ngQuery.ts @@ -18,10 +18,10 @@ export function getInlineStyle(dec: ts.Decorator): Maybe { +export function getTemplate(dec: ts.Decorator): Maybe { return decoratorArgument(dec).bind(expr => getStringInitializerFromProperty('template', expr!.properties)); } -export function getTemplateUrl(dec: ts.Decorator): Maybe { +export function getTemplateUrl(dec: ts.Decorator): Maybe { return decoratorArgument(dec).bind(expr => getStringInitializerFromProperty('templateUrl', expr!.properties)); } diff --git a/src/util/utils.ts b/src/util/utils.ts index 8d47bdf6d..775d808cf 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -1,7 +1,7 @@ import * as ts from 'typescript'; -export const isSimpleTemplateString = (e: any): e is ts.SyntaxKind.FirstTemplateToken | ts.StringLiteralLike => { - return ts.isStringLiteralLike(e) || e.kind === ts.SyntaxKind.FirstTemplateToken; +export const isSimpleTemplateString = (e: any): e is ts.SyntaxKind.FirstTemplateToken | ts.StringLiteral => { + return e.kind === ts.SyntaxKind.StringLiteral || e.kind === ts.SyntaxKind.FirstTemplateToken; }; export const getClassName = (property: ts.PropertyDeclaration): string | undefined => {