Skip to content

Commit

Permalink
refactor: replace/remove deprecated method calls (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelss95 authored and mgechev committed May 16, 2018
1 parent c3a1ffc commit 04f99af
Show file tree
Hide file tree
Showing 37 changed files with 237 additions and 244 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"format:base": "prettier --config ./.prettierrc \"*.{json,md}\" \"src/**/*.{css,scss,ts}\" \"test/**/*.{css,scss,ts}\"",
"format:check": "npm run format:base -- --list-different",
"format:fix": "npm run format:base -- --write",
"lint": "tslint -c tslint.json \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "tslint -p . -c tslint.json \"src/**/*.ts\" \"test/**/*.ts\"",
"lint:fix": "npm run lint -- --fix",
"release": "npm run build && rimraf dist && tsc -p tsconfig-release.json && npm run copy:common && npm run prepare:package && cross-env BUILD_TYPE=prod npm run set:vars",
"build": "rimraf dist && tsc && npm run format:check && npm run lint && npm t",
Expand Down
12 changes: 10 additions & 2 deletions src/angular/ngWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ export class NgWalker extends Lint.RuleWalker {
compiler.templateVisitAll(referenceVisitor, roots, null);
visitor._variables = referenceVisitor.variables;
roots.forEach(r => visitor.visit(r, context.controller));
visitor.getFailures().forEach(f => this.addFailure(f));
visitor
.getFailures()
.forEach(f =>
this.addFailureFromStartToEnd(f.getStartPosition().getPosition(), f.getEndPosition().getPosition(), f.getFailure(), f.getFix())
);
}
}

Expand All @@ -216,7 +220,11 @@ export class NgWalker extends Lint.RuleWalker {
const sourceFile = this.getContextSourceFile(styleMetadata.url, styleMetadata.style.source);
const visitor = new this._config.cssVisitorCtrl(sourceFile, this._originalOptions, context, styleMetadata, baseStart);
style.visit(visitor);
visitor.getFailures().forEach(f => this.addFailure(f));
visitor
.getFailures()
.forEach(f =>
this.addFailureFromStartToEnd(f.getStartPosition().getPosition(), f.getEndPosition().getPosition(), f.getFailure(), f.getFix())
);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/angular/sourceMappingVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class SourceMappingVisitor extends RuleWalker {

createFailure(s: number, l: number, message: string, fix?: Fix): RuleFailure {
const { start, length } = this.getMappedInterval(s, l);
// tslint:disable-next-line:deprecation
return super.createFailure(start, length, message, fix);
}

Expand Down
8 changes: 4 additions & 4 deletions src/angular/styles/cssLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ export class CssLexer {

export function cssScannerError(token: CssToken, message: string): Error {
const error = Error('CssParseError: ' + message);
(error as any)[ERROR_RAW_MESSAGE] = message;
(error as any)[ERROR_TOKEN] = token;
error[ERROR_RAW_MESSAGE] = message;
error[ERROR_TOKEN] = token;
return error;
}

const ERROR_TOKEN = 'ngToken';
const ERROR_RAW_MESSAGE = 'ngRawMessage';

export function getRawMessage(error: Error): string {
return (error as any)[ERROR_RAW_MESSAGE];
return error[ERROR_RAW_MESSAGE];
}

export function getToken(error: Error): CssToken {
return (error as any)[ERROR_TOKEN];
return error[ERROR_TOKEN];
}

function _trackWhitespace(mode: CssLexerMode) {
Expand Down
4 changes: 2 additions & 2 deletions src/angular/styles/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export class CssParser {
this._errors = [];

const result = new ParsedCssResult(errors, ast);
this._file = null as any;
this._scanner = null as any;
this._file = null;
this._scanner = null;
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/angular/templates/basicTemplateAstVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ExpTypes } from '../expressionTypes';
import { ComponentMetadata } from '../metadata';
import { RecursiveAngularExpressionVisitor } from './recursiveAngularExpressionVisitor';
import { SourceMappingVisitor } from '../sourceMappingVisitor';
import { NgWalker } from '../ngWalker';

const getExpressionDisplacement = (binding: any) => {
let attrLen = 0;
Expand Down Expand Up @@ -184,6 +183,7 @@ export class BasicTemplateAstVisitor extends SourceMappingVisitor implements ast
templateVisitor.preDefinedVariables = this._variables;
templateVisitor.parentAST = prop;
templateVisitor.visit(ast);
// tslint:disable-next-line:deprecation
templateVisitor.getFailures().forEach(f => this.addFailure(f));
}
}
3 changes: 0 additions & 3 deletions src/angular/templates/jitReflector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
NgModuleFactory,
NgModuleRef,
QueryList,
Renderer,
SecurityContext,
TRANSLATIONS_FORMAT,
TemplateRef,
Expand Down Expand Up @@ -54,7 +53,6 @@ const builtinExternalReferences = createBuiltinExternalReferencesMap();
export class JitReflector implements CompileReflector {
tryAnnotations: any;
private reflectionCapabilities: ReflectionCapabilities;
private builtinExternalReferences = new Map<ExternalReference, any>();

constructor() {
this.reflectionCapabilities = new ReflectionCapabilities();
Expand Down Expand Up @@ -133,7 +131,6 @@ function createBuiltinExternalReferencesMap() {
map.set(Identifiers.interpolate, ɵinterpolate);
map.set(Identifiers.EMPTY_ARRAY, ɵEMPTY_ARRAY);
map.set(Identifiers.EMPTY_MAP, ɵEMPTY_MAP);
map.set(Identifiers.Renderer, Renderer);
map.set(Identifiers.viewDef, ɵvid);
map.set(Identifiers.elementDef, ɵeld);
map.set(Identifiers.anchorDef, ɵand);
Expand Down
11 changes: 7 additions & 4 deletions src/angular/templates/templateParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const parseTemplate = (template: string, directives: DirectiveDeclaration
ngContentSelectors: this.ngContentSelectors,
encapsulation: this.encapsulation,
summaryKind: summaryKind
} as any;
};
}
};

Expand Down Expand Up @@ -164,10 +164,11 @@ export const parseTemplate = (template: string, directives: DirectiveDeclaration
queries: [],
viewQueries: [],
entryComponents: [],
guards: [],
componentViewType: null,
rendererType: null,
componentFactory: null
} as any),
}),
template,
defaultDirectives,
[],
Expand All @@ -193,10 +194,11 @@ export const parseTemplate = (template: string, directives: DirectiveDeclaration
queries: [],
viewQueries: [],
entryComponents: [],
guards: [],
componentViewType: null,
rendererType: null,
componentFactory: null
} as any),
}),
template,
defaultDirectives,
[],
Expand All @@ -222,10 +224,11 @@ export const parseTemplate = (template: string, directives: DirectiveDeclaration
queries: [],
viewQueries: [],
entryComponents: [],
guards: [],
componentViewType: null,
rendererType: null,
componentFactory: null
} as any),
}),
template,
defaultDirectives,
[],
Expand Down
46 changes: 24 additions & 22 deletions src/angularWhitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { RecursiveAngularExpressionVisitor } from './angular/templates/recursive
// Check if ES6 'y' flag is usable.
const stickyFlagUsable = (() => {
try {
const reg = new RegExp('d', 'y');
const reg = /d/y;
return true;
} catch (e) {
} catch {
return false;
}
})();
Expand Down Expand Up @@ -43,7 +43,7 @@ const checkSemicolonNoWhitespaceWithSticky: CheckSemicolonNoWhitespaceMethod = (
while ((exprMatch = reg.exec(expr))) {
const start = fixedOffset + reg.lastIndex;
const absolutePosition = context.getSourcePosition(start - 1);
context.addFailure(context.createFailure(start, 2, error, getSemicolonReplacements(absolutePosition)));
context.addFailureAt(start, 2, error, getSemicolonReplacements(absolutePosition));
}
};

Expand All @@ -64,7 +64,7 @@ const checkSemicolonNoWhitespaceWithoutSticky: CheckSemicolonNoWhitespaceMethod
if (nextIndex < expr.length && /\S/.test(expr[nextIndex])) {
const start = fixedOffset + nextIndex;
const absolutePosition = context.getSourcePosition(start - 1);
context.addFailure(context.createFailure(start, 2, error, getSemicolonReplacements(absolutePosition)));
context.addFailureAt(start, 2, error, getSemicolonReplacements(absolutePosition));
}

lastIndex = nextIndex;
Expand Down Expand Up @@ -101,13 +101,11 @@ class InterpolationWhitespaceVisitor extends BasicTemplateAstVisitor implements
return;
}
const errorText = length === 0 ? 'Missing' : 'Extra';
context.addFailure(
context.createFailure(
position,
length + lengthFix,
`${errorText} whitespace in interpolation ${location}; expecting ${InterpolationOpen} expr ${InterpolationClose}`,
[new Lint.Replacement(absolutePosition, length + lengthFix, fixTo)]
)
context.addFailureAt(
position,
length + lengthFix,
`${errorText} whitespace in interpolation ${location}; expecting ${InterpolationOpen} expr ${InterpolationClose}`,
[new Lint.Replacement(absolutePosition, length + lengthFix, fixTo)]
);
};

Expand Down Expand Up @@ -141,7 +139,7 @@ class InterpolationWhitespaceVisitor extends BasicTemplateAstVisitor implements
class SemicolonTemplateVisitor extends BasicTemplateAstVisitor implements ConfigurableVisitor {
visitDirectiveProperty(prop: ast.BoundDirectivePropertyAst, context: BasicTemplateAstVisitor): any {
if (prop.sourceSpan) {
const directive = (<any>prop.sourceSpan).toString();
const directive = prop.sourceSpan.toString();
const match = /^([^=]+=\s*)([^]*?)\s*$/.exec(directive);
const rawExpression = match[2];
const positionFix = match[1].length + 1;
Expand Down Expand Up @@ -173,7 +171,9 @@ class WhitespaceTemplateVisitor extends BasicTemplateAstVisitor {
.filter(v => options.indexOf(v.getOption()) >= 0)
.map(v => v.visitBoundText(text, this))
.filter(f => !!f)
.forEach(f => this.addFailure(f));
.forEach(f =>
this.addFailureFromStartToEnd(f.getStartPosition().getPosition(), f.getEndPosition().getPosition(), f.getFailure(), f.getFix())
);
super.visitBoundText(text, context);
}

Expand All @@ -183,7 +183,9 @@ class WhitespaceTemplateVisitor extends BasicTemplateAstVisitor {
.filter(v => options.indexOf(v.getOption()) >= 0)
.map(v => v.visitDirectiveProperty(prop, this))
.filter(f => !!f)
.forEach(f => this.addFailure(f));
.forEach(f =>
this.addFailureFromStartToEnd(f.getStartPosition().getPosition(), f.getEndPosition().getPosition(), f.getFailure(), f.getFix())
);
super.visitDirectiveProperty(prop, context);
}
}
Expand Down Expand Up @@ -238,13 +240,11 @@ class PipeWhitespaceVisitor extends RecursiveAngularExpressionVisitor implements
}

if (replacements.length) {
context.addFailure(
context.createFailure(
ast.exp.span.end - 1,
3,
'The pipe operator should be surrounded by one space on each side, i.e. " | ".',
replacements
)
context.addFailureAt(
ast.exp.span.end - 1,
3,
'The pipe operator should be surrounded by one space on each side, i.e. " | ".',
replacements
);
}
super.visitPipe(ast, context);
Expand Down Expand Up @@ -272,7 +272,9 @@ class TemplateExpressionVisitor extends RecursiveAngularExpressionVisitor {
.filter(v => options.indexOf(v.getOption()) >= 0)
.map(v => v.visitPipe(expr, this))
.filter(f => !!f)
.forEach(f => this.addFailure(f));
.forEach(f =>
this.addFailureFromStartToEnd(f.getStartPosition().getPosition(), f.getEndPosition().getPosition(), f.getFailure(), f.getFix())
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bananaInBoxRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const InvalidSyntaxBoxOpen = '([';
const InvalidSyntaxBoxClose = '])';
const ValidSyntaxOpen = '[(';
const ValidSyntaxClose = ')]';
const InvalidSyntaxBoxRe = new RegExp('\\[(.*?)\\]');
const InvalidSyntaxBoxRe = /\[(.*?)\]/;

const getReplacements = (text: ast.BoundEventAst, absolutePosition: number) => {
const expr: string = (text.sourceSpan as any).toString();
const expr = text.sourceSpan.toString();
const internalStart = expr.indexOf(InvalidSyntaxBoxOpen);
const internalEnd = expr.lastIndexOf(InvalidSyntaxBoxClose);
const len = internalEnd - internalStart - InvalidSyntaxBoxClose.length;
Expand All @@ -35,12 +35,12 @@ class BananaInBoxTemplateVisitor extends BasicTemplateAstVisitor {
}

if (error) {
const expr: any = (<any>prop.sourceSpan).toString();
const expr = prop.sourceSpan.toString();
const internalStart = expr.indexOf(InvalidSyntaxBoxOpen) + 1;
const start = prop.sourceSpan.start.offset + internalStart;
const absolutePosition = this.getSourcePosition(start - 1);

this.addFailure(this.createFailure(start, expr.trim().length, error, getReplacements(prop, absolutePosition)));
this.addFailureAt(start, expr.trim().length, error, getReplacements(prop, absolutePosition));
}
}
super.visitEvent(prop, context);
Expand Down
Loading

0 comments on commit 04f99af

Please sign in to comment.