Skip to content

Commit

Permalink
style: prettier pass (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgechev authored Sep 30, 2020
1 parent cd88bd5 commit 5bfc15c
Show file tree
Hide file tree
Showing 149 changed files with 1,425 additions and 1,350 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ import { Component } from '@angular/core';

@Component({
selector: 'codelyzer',
template: `
<h1>Hello {{ name }}!</h1>
`
template: ` <h1>Hello {{ name }}!</h1> `,
})
class Codelyzer {
name: string = 'World';
Expand Down Expand Up @@ -355,7 +353,7 @@ import { Component } from '@angular/core';
/* tslint:disable:template-use-track-by-function */
@Component({
selector: 'codelyzer',
templateUrl: './codelyzer.component.html'
templateUrl: './codelyzer.component.html',
})
class Codelyzer {}
```
Expand Down Expand Up @@ -408,7 +406,7 @@ module.exports = {
predefinedDirectives: [{ selector: 'form', exportAs: 'ngForm' }],

// None = 0b000, Error = 0b001, Info = 0b011, Debug = 0b111
logLevel: 0b111
logLevel: 0b111,
};
```

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

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"mocha": "6.2.1",
"ncp": "2.0.0",
"node-sass": "4.13.0",
"prettier": "1.19.1",
"prettier": "2.1.2",
"rimraf": "3.0.0",
"rxjs": "6.5.3",
"standard-version": "7.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/angular/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let BUILD_TYPE = '<%= BUILD_TYPE %>';
type FileExtension = typeof CSS_FILE_EXTENSION | typeof HTML_FILE_EXTENSION | typeof SVG_FILE_EXTENSION;

const transform = (code: string, fileExtensions: ReadonlyArray<FileExtension>, url?: string): { code: string; url?: string } => {
const parsedCode = !url || fileExtensions.some(fileExtension => url.endsWith(fileExtension)) ? code : '';
const parsedCode = !url || fileExtensions.some((fileExtension) => url.endsWith(fileExtension)) ? code : '';

return { code: parsedCode, url };
};
Expand Down Expand Up @@ -77,14 +77,14 @@ export const Config: Config = {
{ selector: 'md-button-toggle-group:not([multiple])', exportAs: 'mdButtonToggleGroup' },
{ selector: '[md-menu-trigger-for], [mdMenuTriggerFor]', exportAs: 'mdMenuTrigger' },
{ selector: '[md-tooltip], [mdTooltip]', exportAs: 'mdTooltip' },
{ selector: 'md-select', exportAs: 'mdSelect' }
{ selector: 'md-select', exportAs: 'mdSelect' },
],

resolveUrl: (url: string | null) => url,

transformStyle: (code: string, url?: string) => transform(code, [CSS_FILE_EXTENSION], url),

transformTemplate: (code: string, url?: string) => transform(code, [HTML_FILE_EXTENSION, SVG_FILE_EXTENSION], url)
transformTemplate: (code: string, url?: string) => transform(code, [HTML_FILE_EXTENSION, SVG_FILE_EXTENSION], url),
};

try {
Expand Down
2 changes: 1 addition & 1 deletion src/angular/expressionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ export const ExpTypes = {

ASTWithSource(ast: any) {
return ast.constructor.name === 'ASTWithSource';
}
},
};
46 changes: 23 additions & 23 deletions src/angular/metadataReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ModuleMetadata,
PipeMetadata,
StyleMetadata,
TemplateMetadata
TemplateMetadata,
} from './metadata';
import { AbstractResolver, MetadataUrls } from './urlResolvers/abstractResolver';
import { PathResolver } from './urlResolvers/pathResolver';
Expand All @@ -38,7 +38,7 @@ export class MetadataReader {

read(d: ts.ClassDeclaration): DirectiveMetadata | ComponentMetadata | PipeMetadata | ModuleMetadata | InjectableMetadata | undefined {
const componentMetadata = unwrapFirst<ComponentMetadata | undefined>(
maybeNodeArray(ts.createNodeArray(d.decorators)).map(dec => {
maybeNodeArray(ts.createNodeArray(d.decorators)).map((dec) => {
return Maybe.lift(dec)
.bind(callExpression)
.bind(withIdentifier('Component') as any)
Expand All @@ -47,7 +47,7 @@ export class MetadataReader {
);

const directiveMetadata = unwrapFirst<DirectiveMetadata | undefined>(
maybeNodeArray(ts.createNodeArray(d.decorators)).map(dec =>
maybeNodeArray(ts.createNodeArray(d.decorators)).map((dec) =>
Maybe.lift(dec)
.bind(callExpression)
.bind(withIdentifier('Directive') as any)
Expand All @@ -56,7 +56,7 @@ export class MetadataReader {
);

const pipeMetadata = unwrapFirst<PipeMetadata | undefined>(
maybeNodeArray(ts.createNodeArray(d.decorators)).map(dec =>
maybeNodeArray(ts.createNodeArray(d.decorators)).map((dec) =>
Maybe.lift(dec)
.bind(callExpression)
.bind(withIdentifier('Pipe') as any)
Expand All @@ -65,7 +65,7 @@ export class MetadataReader {
);

const moduleMetadata = unwrapFirst<ModuleMetadata | undefined>(
maybeNodeArray(ts.createNodeArray(d.decorators)).map(dec =>
maybeNodeArray(ts.createNodeArray(d.decorators)).map((dec) =>
Maybe.lift(dec)
.bind(callExpression)
.bind(withIdentifier('NgModule') as any)
Expand All @@ -74,7 +74,7 @@ export class MetadataReader {
);

const injectableMetadata = unwrapFirst<InjectableMetadata | undefined>(
maybeNodeArray(ts.createNodeArray(d.decorators)).map(dec =>
maybeNodeArray(ts.createNodeArray(d.decorators)).map((dec) =>
Maybe.lift(dec)
.bind(callExpression)
.bind(withIdentifier('Injectable') as any)
Expand Down Expand Up @@ -117,8 +117,8 @@ export class MetadataReader {
const directiveMetadata = this.readDirectiveMetadata(d, dec);
const external_M = expr.fmap(() => this.urlResolver!.resolve(dec));
const animations_M = external_M.bind(() => this.readComponentAnimationsMetadata(dec));
const style_M = external_M.bind(external => this.readComponentStylesMetadata(dec, external!));
const template_M = external_M.bind(external => this.readComponentTemplateMetadata(dec, external!));
const style_M = external_M.bind((external) => this.readComponentStylesMetadata(dec, external!));
const template_M = external_M.bind((external) => this.readComponentTemplateMetadata(dec, external!));

return new ComponentMetadata(
directiveMetadata.controller,
Expand All @@ -135,59 +135,59 @@ export class MetadataReader {
}

protected readComponentAnimationsMetadata(dec: ts.Decorator): Maybe<(AnimationMetadata | undefined)[] | undefined> {
return getAnimations(dec).fmap(inlineAnimations =>
inlineAnimations!.elements.filter(isStringLiteralLike).map<AnimationMetadata>(inlineAnimation => ({
return getAnimations(dec).fmap((inlineAnimations) =>
inlineAnimations!.elements.filter(isStringLiteralLike).map<AnimationMetadata>((inlineAnimation) => ({
animation: normalizeTransformed({ code: (inlineAnimation as ts.StringLiteral).text }),
node: inlineAnimation as ts.Node
node: inlineAnimation as ts.Node,
}))
);
}

protected readComponentTemplateMetadata(dec: ts.Decorator, external: MetadataUrls): Maybe<TemplateMetadata | undefined> {
// Resolve Inline template
return getTemplate(dec)
.fmap<TemplateMetadata>(inlineTemplate => ({
.fmap<TemplateMetadata>((inlineTemplate) => ({
node: inlineTemplate,
template: normalizeTransformed(Config.transformTemplate(inlineTemplate!.text)),
url: undefined
url: undefined,
}))
.catch(() =>
// If there's no valid inline template, we resolve external template
Maybe.lift(external.templateUrl).bind(url =>
this._resolve(url!).fmap<TemplateMetadata>(template => ({
Maybe.lift(external.templateUrl).bind((url) =>
this._resolve(url!).fmap<TemplateMetadata>((template) => ({
node: undefined,
template: normalizeTransformed(Config.transformTemplate(template!, url)),
url
url,
}))
)
);
}

protected readComponentStylesMetadata(dec: ts.Decorator, external: MetadataUrls): Maybe<(StyleMetadata | undefined)[] | undefined> {
return getInlineStyle(dec)
.fmap(inlineStyles =>
.fmap((inlineStyles) =>
// Resolve Inline styles
inlineStyles!.elements.filter(isStringLiteralLike).map<StyleMetadata>(inlineStyle => ({
inlineStyles!.elements.filter(isStringLiteralLike).map<StyleMetadata>((inlineStyle) => ({
node: inlineStyle,
style: normalizeTransformed(Config.transformStyle((inlineStyle as ts.StringLiteral).text))
style: normalizeTransformed(Config.transformStyle((inlineStyle as ts.StringLiteral).text)),
}))
)
.catch(() =>
// If there's no valid inline styles, we resolve external styles
Maybe.lift(external.styleUrls)
.fmap(urls =>
.fmap((urls) =>
urls.map((
url // Resolve each style URL and transform to metadata
) =>
this._resolve(url).fmap<StyleMetadata>(style => ({
this._resolve(url).fmap<StyleMetadata>((style) => ({
node: undefined,
style: normalizeTransformed(Config.transformStyle(style!, url)),
url
url,
}))
)
)
// merge Maybe<StyleMetadata>[] to Maybe<StyleMetadata[]>
.bind(url => listToMaybe(url as any) as any)
.bind((url) => listToMaybe(url as any) as any)
);
}

Expand Down
14 changes: 7 additions & 7 deletions src/angular/ngWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getDecoratorStringArgs = (decorator: ts.Decorator): string[] => {
const { expression } = decorator;
const args = ts.isCallExpression(expression) ? expression.arguments : ts.createNodeArray();

return args.filter(ts.isStringLiteral).map(x => x.text);
return args.filter(ts.isStringLiteral).map((x) => x.text);
};

const getPosition = (node: ts.Node) => {
Expand Down Expand Up @@ -54,7 +54,7 @@ export class NgWalker extends Lint.RuleWalker {
{
cssVisitorCtrl: BasicCssAstVisitor,
templateVisitorCtrl: BasicTemplateAstVisitor,
expressionVisitorCtrl: RecursiveAngularExpressionVisitor
expressionVisitorCtrl: RecursiveAngularExpressionVisitor,
},
this._config || {}
);
Expand Down Expand Up @@ -132,7 +132,7 @@ export class NgWalker extends Lint.RuleWalker {
this.visitNgStyleHelper(cssAst, metadata, style!, getPosition(style!.node!));
} catch (e) {
const {
controller: { name }
controller: { name },
} = metadata;
const text = name && ts.isIdentifier(name) ? name.text : '';

Expand All @@ -148,7 +148,7 @@ export class NgWalker extends Lint.RuleWalker {
this.visitNgTemplateHelper(templateAst, metadata, getPosition(template.node!));
} catch (e) {
const {
controller: { name }
controller: { name },
} = metadata;
const text = name && ts.isIdentifier(name) ? name.text : '';

Expand Down Expand Up @@ -199,9 +199,9 @@ export class NgWalker extends Lint.RuleWalker {
);
compiler.templateVisitAll(referenceVisitor, roots, null);
visitor._variables = referenceVisitor.variables;
roots.forEach(r => visitor.visit(r, context.controller));
roots.forEach((r) => visitor.visit(r, context.controller));
// tslint:disable-next-line:deprecation
visitor.getFailures().forEach(f => this.addFailure(f));
visitor.getFailures().forEach((f) => this.addFailure(f));
}

protected visitNgStyleHelper(style: CssAst, context: ComponentMetadata, styleMetadata: StyleMetadata, baseStart: number) {
Expand All @@ -213,7 +213,7 @@ export class NgWalker extends Lint.RuleWalker {
const visitor = new this._config!.cssVisitorCtrl!(sourceFile, this._originalOptions, context, styleMetadata, baseStart);
style.visit(visitor);
// tslint:disable-next-line:deprecation
visitor.getFailures().forEach(f => this.addFailure(f));
visitor.getFailures().forEach((f) => this.addFailure(f));
}

protected getContextSourceFile(path: string, content: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/angular/ngWalkerFactoryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ngWalkerFactoryUtils = {
return {
templateVisitorCtrl: BasicTemplateAstVisitor,
expressionVisitorCtrl: RecursiveAngularExpressionVisitor,
cssVisitorCtrl: BasicCssAstVisitor
cssVisitorCtrl: BasicCssAstVisitor,
};
},

Expand All @@ -24,5 +24,5 @@ export const ngWalkerFactoryUtils = {

normalizeConfig(config: NgWalkerConfig) {
return Object.assign(this.defaultConfig(), config || {});
}
},
};
2 changes: 1 addition & 1 deletion src/angular/sourceMappingVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function computeLineAndCharacterOfPosition(lineStarts: number[], position: numbe
}
return {
character: position - lineStarts[lineNumber],
line: lineNumber
line: lineNumber,
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/angular/styles/cssAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum BlockType {
Page,
Document,
Viewport,
Unsupported
Unsupported,
}

export interface CssAstVisitor {
Expand Down Expand Up @@ -146,7 +146,7 @@ export class CssSelectorRuleAst extends CssBlockRuleAst {

constructor(location: ParseSourceSpan, public selectors: CssSelectorAst[], block: CssBlockAst) {
super(location, BlockType.Selector, block);
this.strValue = selectors.map(selector => selector.strValue).join(',');
this.strValue = selectors.map((selector) => selector.strValue).join(',');
}
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssSelectorRule(this, context);
Expand All @@ -172,7 +172,7 @@ export class CssSelectorAst extends CssSelectorPartAst {
public strValue: string;
constructor(location: ParseSourceSpan, public selectorParts: CssSimpleSelectorAst[]) {
super(location);
this.strValue = selectorParts.map(part => part.strValue).join('');
this.strValue = selectorParts.map((part) => part.strValue).join('');
}
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssSelector(this, context);
Expand Down
4 changes: 2 additions & 2 deletions src/angular/styles/cssLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export enum CssTokenType {
AtKeyword,
Character,
Whitespace,
Invalid
Invalid,
}

export enum CssLexerMode {
Expand All @@ -37,7 +37,7 @@ export enum CssLexerMode {
STYLE_BLOCK,
STYLE_VALUE,
STYLE_VALUE_FUNCTION,
STYLE_CALC_FUNCTION
STYLE_CALC_FUNCTION,
}

export class LexedCssResult {
Expand Down
10 changes: 5 additions & 5 deletions src/angular/styles/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
CssStylesBlockAst,
CssUnknownRuleAst,
CssUnknownTokenListAst,
mergeTokens
mergeTokens,
} from './cssAst';

const SPACE_OPERATOR = ' ';
Expand Down Expand Up @@ -334,12 +334,12 @@ export class CssParser {
token
);

this._collectUntilDelim(delimiters | LBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG).forEach(token => {
this._collectUntilDelim(delimiters | LBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG).forEach((token) => {
listOfTokens.push(token);
});
if (this._scanner!.peek == chars.$LBRACE) {
listOfTokens.push(this._consume(CssTokenType.Character, '{'));
this._collectUntilDelim(delimiters | RBRACE_DELIM_FLAG | LBRACE_DELIM_FLAG).forEach(token => {
this._collectUntilDelim(delimiters | RBRACE_DELIM_FLAG | LBRACE_DELIM_FLAG).forEach((token) => {
listOfTokens.push(token);
});
listOfTokens.push(this._consume(CssTokenType.Character, '}'));
Expand Down Expand Up @@ -518,7 +518,7 @@ export class CssParser {
}

// :host(a, b, c) {
this._parseSelectors(innerDelims).forEach(selector => {
this._parseSelectors(innerDelims).forEach((selector) => {
innerSelectors.push(selector);
});
} else {
Expand Down Expand Up @@ -877,7 +877,7 @@ export class CssParser {

const remainingTokens = this._collectUntilDelim(delimiters | COLON_DELIM_FLAG | SEMICOLON_DELIM_FLAG, CssTokenType.Identifier);
if (remainingTokens.length > 0) {
remainingTokens.forEach(token => {
remainingTokens.forEach((token) => {
propStr.push(token.strValue);
});
}
Expand Down
Loading

0 comments on commit 5bfc15c

Please sign in to comment.