Skip to content

Commit

Permalink
chore: enable strict (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelss95 authored and mgechev committed May 30, 2018
1 parent eaed2d5 commit da0f553
Show file tree
Hide file tree
Showing 79 changed files with 923 additions and 1,036 deletions.
2 changes: 1 addition & 1 deletion build/buildDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import * as path from 'path';

import { IFormatterMetadata, IRuleMetadata } from 'tslint';

type Metadata = IRuleMetadata | IFormatterMetadata;
type Metadata = IRuleMetadata | IFormatterMetadata | undefined;

interface Documented {
metadata: Metadata;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/app-linter/html-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class HtmlFormatter implements Formatter {
}

private linkify(inputText: string) {
let replacedText: string, replacePattern1: RegExp, replacePattern2: RegExp, replacePattern3: RegExp;
let replacedText: string, replacePattern1: RegExp, replacePattern2: RegExp;

// URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
Expand Down
5 changes: 1 addition & 4 deletions docs/src/app-linter/linter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Formatter } from './formatter-interface';
import { RichEditor } from './rich-editor-interface';
import { Reporter } from './reporter-interface';

export interface LinterConfig {
textEditor: RichEditor;
Expand All @@ -9,8 +7,7 @@ export interface LinterConfig {
}

export class Linter {
private worker: Worker;
private widgets: any[] = [];
private worker!: Worker;
private errorId = 0;

constructor(private config: LinterConfig) {}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/app-linter/plain-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export class PlainReporter implements Reporter {
}

highlight(id: any) {
document.getElementById(id).classList.add('error-highlight');
document.getElementById(id)!.classList.add('error-highlight');
}

dropHighlight(id: any) {
document.getElementById(id).classList.remove('error-highlight');
document.getElementById(id)!.classList.remove('error-highlight');
}
}
2 changes: 1 addition & 1 deletion docs/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const editor = new ErrorReportingEditor(
theme: 'material',
lineNumbers: true
}) as Editor,
new PlainReporter(new HtmlFormatter(), document.getElementById('warnings-header'), document.getElementById('warnings'))
new PlainReporter(new HtmlFormatter(), document.getElementById('warnings-header')!, document.getElementById('warnings')!)
);

let unlocked = true;
Expand Down
13 changes: 5 additions & 8 deletions docs/src/worker/web-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ts from 'typescript';
import * as Linter from 'tslint';
import { LintResult } from 'tslint';

export function getSourceFile(fileName: string, source: string): ts.SourceFile {
export function getSourceFile(fileName: string, source: string): ts.SourceFile | undefined {
const normalizedName = fileName;
const compilerOptions = createCompilerOptions();

Expand All @@ -15,14 +15,11 @@ export function getSourceFile(fileName: string, source: string): ts.SourceFile {
getDirectories: (_path: string) => [],
getNewLine: () => '\n',
getSourceFile: (filenameToGet: string) => {
if (filenameToGet === normalizedName) {
return ts.createSourceFile(filenameToGet, source, compilerOptions.target, true);
}
return undefined;
return filenameToGet === normalizedName ? ts.createSourceFile(filenameToGet, source, compilerOptions.target!, true) : undefined;
},
readFile: () => null,
readFile: () => undefined,
useCaseSensitiveFileNames: () => true,
writeFile: () => null
writeFile: () => undefined
};

const program = ts.createProgram([normalizedName], compilerOptions, compilerHost);
Expand All @@ -40,7 +37,7 @@ export class WebLinter {
private failures: Linter.RuleFailure[] = [];

public lint(fileName: string, source: string, enabledRules: any): void {
let sourceFile: ts.SourceFile = getSourceFile(fileName, source);
let sourceFile = getSourceFile(fileName, source);

if (sourceFile === undefined) {
throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts or .tsx extension.`);
Expand Down
70 changes: 33 additions & 37 deletions src/angular/config.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,44 @@
import * as ts from 'typescript';
import { CodeWithSourceMap } from './metadata';

export interface UrlResolver {
(url: string, d: ts.Decorator): string;
export interface StyleTransformer {
(style: string, url?: string): CodeWithSourceMap;
}

export interface TemplateTransformer {
(template: string, url: string, d: ts.Decorator): CodeWithSourceMap;
(template: string, url?: string): CodeWithSourceMap;
}

export interface StyleTransformer {
(style: string, url: string, d: ts.Decorator): CodeWithSourceMap;
export interface UrlResolver {
(url: string | null): string | null;
}

export const LogLevel = {
None: 0,
Error: 0b001,
Info: 0b011,
Debug: 0b111
};
export const LogLevel = { Debug: 0b111, Error: 0b001, Info: 0b011, None: 0 };

export interface Config {
interpolation: [string, string];
logLevel: number;
predefinedDirectives: DirectiveDeclaration[];
resolveUrl: UrlResolver;
transformTemplate: TemplateTransformer;
transformStyle: StyleTransformer;
predefinedDirectives: DirectiveDeclaration[];
logLevel: number;
transformTemplate: TemplateTransformer;
}

export interface DirectiveDeclaration {
selector: string;
exportAs?: string;
inputs?: string[];
outputs?: string[];
hostProperties?: string[];
hostAttributes?: string[];
hostListeners?: string[];
hostProperties?: string[];
inputs?: string[];
outputs?: string[];
selector: string;
}

let BUILD_TYPE = '<%= BUILD_TYPE %>';

export const Config: Config = {
interpolation: ['{{', '}}'],

resolveUrl(url: string, d: ts.Decorator) {
return url;
},

transformTemplate(code: string, url: string, d: ts.Decorator) {
if (!url || url.endsWith('.html')) {
return { code, url };
}
return { code: '', url };
},

transformStyle(code: string, url: string, d: ts.Decorator) {
if (!url || url.endsWith('.css')) {
return { code, url };
}
return { code: '', url };
},
logLevel: BUILD_TYPE === 'dev' ? LogLevel.Debug : LogLevel.None,

predefinedDirectives: [
{ selector: 'form:not([ngNoForm]):not([formGroup]), ngForm, [ngForm]', exportAs: 'ngForm' },
Expand Down Expand Up @@ -89,7 +67,25 @@ export const Config: Config = {
{ selector: 'md-select', exportAs: 'mdSelect' }
],

logLevel: BUILD_TYPE === 'dev' ? LogLevel.Debug : LogLevel.None
resolveUrl(url: string | null) {
return url;
},

transformStyle(code: string, url?: string) {
if (!url || url.endsWith('.css')) {
return { code, url };
}

return { code: '', url };
},

transformTemplate(code: string, url?: string) {
if (!url || url.endsWith('.html')) {
return { code, url };
}

return { code: '', url };
}
};

try {
Expand Down
29 changes: 12 additions & 17 deletions src/angular/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,30 @@ import { RawSourceMap } from 'source-map';

export interface CodeWithSourceMap {
code: string;
source?: string;
map?: RawSourceMap;
source?: string;
}

export interface TemplateMetadata {
template: CodeWithSourceMap;
node: ts.Node;
url: string;
interface PropertyMetadata {
node?: ts.Node;
url?: string;
}

export interface StyleMetadata {
export interface StyleMetadata extends PropertyMetadata {
style: CodeWithSourceMap;
node: ts.Node;
url: string;
}

export interface StylesMetadata {
[index: number]: StyleMetadata;
length: number;
push(e: StyleMetadata): number;
export interface TemplateMetadata extends PropertyMetadata {
template: CodeWithSourceMap;
}

export class DirectiveMetadata {
selector: string;
controller: ts.ClassDeclaration;
decorator: ts.Decorator;
controller!: ts.ClassDeclaration;
decorator!: ts.Decorator;
selector!: string;
}

export class ComponentMetadata extends DirectiveMetadata {
template: TemplateMetadata;
styles: StylesMetadata;
styles!: StyleMetadata[];
template!: TemplateMetadata;
}
Loading

0 comments on commit da0f553

Please sign in to comment.