refactor(docs-infra): update docs examples `tslint.json` to match CLI and fix failures (#38143)

This commit updates the `tslint.json` configuration file, that is used
to lint the docs examples, to match the one generated for new Angular
CLI apps. There are some minimal differences (marked with `TODO`
comments) for things, such as component selector prefix, that would
require extensive and/or difficult to validate changes in guides.

This commit also includes the final adjustments to make the docs
examples code compatible with the new tslint rules. (The bulk of the
work has been done in previous commits.)

PR Close #38143
This commit is contained in:
George Kalpakas 2020-07-30 13:03:23 +03:00 committed by Alex Rickabaugh
parent bfd13c06e1
commit 3a46c2da7c
12 changed files with 323 additions and 155 deletions

View File

@ -24,8 +24,7 @@ describe('AngularJS to Angular Quick Reference Tests', () => {
// Go through the samples // Go through the samples
const movieRows = getMovieRows(); const movieRows = getMovieRows();
for (let i = 0; i < expectedSamples.length; i++) { for (const sample of expectedSamples) {
const sample = expectedSamples[i];
const tableCell = movieRows.get(sample.row) const tableCell = movieRows.get(sample.row)
.all(by.tagName('td')).get(sample.column); .all(by.tagName('td')).get(sample.column);
// Check the cell or its nested element // Check the cell or its nested element

View File

@ -76,11 +76,7 @@ export class AppComponent implements OnInit {
} }
giveNullCustomerValue() { giveNullCustomerValue() {
!(this.nullCustomer = null) ? (this.nullCustomer = 'Kelly') : (this.nullCustomer = null); this.nullCustomer = 'Kelly';
}
resetNullItem() {
this.nullCustomer = null;
} }
resetItems() { resetItems() {

View File

@ -1,4 +1,4 @@
/* tslint:disable: no-unused-variable component-selector one-line space-before-function-paren */ // tslint:disable: component-selector space-before-function-paren
// #docplaster // #docplaster
// #docregion // #docregion
import { Component, forwardRef, Optional, SkipSelf } from '@angular/core'; import { Component, forwardRef, Optional, SkipSelf } from '@angular/core';

View File

@ -27,9 +27,9 @@ import { useInjector } from './car-injector';
providers: [Car, Engine, Tires] providers: [Car, Engine, Tires]
}) })
export class CarComponent { export class CarComponent {
factoryCar = (new CarFactory).createCar(); factoryCar = (new CarFactory()).createCar();
injectorCar = useInjector(); injectorCar = useInjector();
noDiCar = new CarNoDi; noDiCar = new CarNoDi();
simpleCar = simpleCar(); simpleCar = simpleCar();
superCar = superCar(); superCar = superCar();
testCar = testCar(); testCar = testCar();

View File

@ -90,7 +90,7 @@ function compileAndCreate() {
* The (almost) same tests for both. * The (almost) same tests for both.
* Only change: the way that the first hero is clicked * Only change: the way that the first hero is clicked
*/ */
function tests(heroClick: Function) { function tests(heroClick: () => void) {
it('should NOT have heroes before ngOnInit', () => { it('should NOT have heroes before ngOnInit', () => {
expect(comp.heroes.length).toBe(0, expect(comp.heroes.length).toBe(0,

View File

@ -147,7 +147,7 @@ describe('Angular async helper', () => {
// #docregion async-test-promise-then // #docregion async-test-promise-then
describe('test jsonp', () => { describe('test jsonp', () => {
function jsonp(url: string, callback: Function) { function jsonp(url: string, callback: () => void) {
// do a jsonp call which is not zone aware // do a jsonp call which is not zone aware
} }
// need to config __zone_symbol__supportWaitUnResolvedChainedPromise flag // need to config __zone_symbol__supportWaitUnResolvedChainedPromise flag

View File

@ -1,3 +1,4 @@
// tslint:disable-next-line: no-namespace
declare namespace jasmine { declare namespace jasmine {
interface Matchers<T> { interface Matchers<T> {
toHaveText(actual: any, expectationFailOutput?: any): jasmine.CustomMatcher; toHaveText(actual: any, expectationFailOutput?: any): jasmine.CustomMatcher;

View File

@ -1,3 +1,4 @@
// tslint:disable-next-line: no-reference
/// <reference path="./jasmine-matchers.d.ts" /> /// <reference path="./jasmine-matchers.d.ts" />
//// Jasmine Custom Matchers //// //// Jasmine Custom Matchers ////

View File

@ -1,28 +1,61 @@
{ {
"rulesDirectory": [ "extends": "tslint:recommended",
"../../node_modules/codelyzer"
],
"rules": { "rules": {
"class-name": true, "align": {
"comment-format": [ "options": [
true, "parameters",
"check-space" "statements"
], ]
},
"array-type": false,
"arrow-return-shorthand": true,
"curly": true, "curly": true,
"eofline": true, "deprecation": {
"forin": true, "severity": "warning"
"indent": [ },
"component-class-suffix": true,
"component-selector": [
true, true,
"spaces" "element",
// TODO: Fix the code and change the prefix to `"app"` (or whatever makes sense).
"",
"kebab-case"
], ],
"label-position": true, "contextual-lifecycle": true,
"directive-class-suffix": true,
"directive-selector": [
true,
"attribute",
["app", "toh"],
"camelCase"
],
"eofline": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false,
"max-line-length": [ "max-line-length": [
true, true,
140 140
], ],
"member-access": false, "member-ordering": [
"no-arg": true, true,
"no-bitwise": true, {
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-console": [ "no-console": [
true, true,
"debug", "debug",
@ -31,63 +64,86 @@
"timeEnd", "timeEnd",
"trace" "trace"
], ],
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": false, "no-empty": false,
"no-eval": true, "no-inferrable-types": [
"no-inferrable-types": true,
"no-string-literal": false,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true, true,
"check-open-brace", "ignore-params"
"check-catch", ],
"check-else", "no-non-null-assertion": true,
"check-whitespace" "no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
], ],
"quotemark": [ "quotemark": [
true, true,
"single" "single"
], ],
"radix": true, "semicolon": {
"semicolon": [ "options": [
"always" "always"
], ]
"triple-equals": [ },
true, "space-before-function-paren": {
"allow-null-check" "options": {
], "anonymous": "never",
"typedef-whitespace": [ "asyncArrow": "always",
true, "constructor": "never",
{ "method": "never",
"call-signature": "nospace", "named": "never"
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
} }
], },
"variable-name": false, "typedef-whitespace": {
"whitespace": [ "options": [
true, {
"check-branch", "call-signature": "nospace",
"check-decl", "index-signature": "nospace",
"check-operator", "parameter": "nospace",
"check-separator", "property-declaration": "nospace",
"check-type" "variable-declaration": "nospace"
], },
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-pascal-case"
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
},
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-inputs-metadata-property": true, "no-inputs-metadata-property": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-outputs-metadata-property": true, "no-outputs-metadata-property": true,
"use-life-cycle-interface": true, "template-banana-in-box": true,
"use-pipe-transform-interface": true, "template-no-negated-async": true,
"component-class-suffix": true, "use-lifecycle-interface": true,
"directive-class-suffix": true, "use-pipe-transform-interface": true
"import-destructuring-spacing": true },
} "rulesDirectory": [
"codelyzer"
]
} }

View File

@ -51,7 +51,7 @@ import { isPlatformBrowser } from '@angular/common';
export class AppModule { export class AppModule {
// #docregion platform-detection // #docregion platform-detection
constructor( constructor(
@Inject(PLATFORM_ID) private platformId: Object, @Inject(PLATFORM_ID) private platformId: object,
@Inject(APP_ID) private appId: string) { @Inject(APP_ID) private appId: string) {
const platform = isPlatformBrowser(platformId) ? const platform = isPlatformBrowser(platformId) ?
'in the browser' : 'on the server'; 'in the browser' : 'on the server';

View File

@ -1,37 +1,50 @@
{ {
"extends": "tslint:recommended", "extends": "tslint:recommended",
"rules": { "rules": {
"align": {
"options": [
"parameters",
"statements"
]
},
"array-type": false, "array-type": false,
"arrow-parens": false, "arrow-return-shorthand": true,
"curly": true,
"deprecation": { "deprecation": {
"severity": "warning" "severity": "warning"
}, },
"component-class-suffix": true, "component-class-suffix": true,
"component-selector": [
true,
"element",
// TODO: Fix the code and change the prefix to `"app"` (or whatever makes sense).
"",
"kebab-case"
],
"contextual-lifecycle": true, "contextual-lifecycle": true,
"directive-class-suffix": true, "directive-class-suffix": true,
"directive-selector": [ "directive-selector": [
true, true,
"attribute", "attribute",
"app", ["app", "toh"],
"camelCase" "camelCase"
], ],
"component-selector": [ "eofline": true,
true,
"element",
"app",
"kebab-case"
],
"import-blacklist": [ "import-blacklist": [
true, true,
"rxjs/Rx" "rxjs/Rx"
], ],
"interface-name": false, "import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false, "max-classes-per-file": false,
"max-line-length": [ "max-line-length": [
true, true,
140 140
], ],
"member-access": false,
"member-ordering": [ "member-ordering": [
true, true,
{ {
@ -43,7 +56,6 @@
] ]
} }
], ],
"no-consecutive-blank-lines": false,
"no-console": [ "no-console": [
true, true,
"debug", "debug",
@ -65,13 +77,59 @@
true, true,
"as-needed" "as-needed"
], ],
"object-literal-sort-keys": false,
"ordered-imports": false,
"quotemark": [ "quotemark": [
true, true,
"single" "single"
], ],
"trailing-comma": false, "semicolon": {
"options": [
"always"
]
},
"space-before-function-paren": {
"options": {
"anonymous": "never",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}
},
"typedef-whitespace": {
"options": [
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-pascal-case"
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
},
"no-conflicting-lifecycle": true, "no-conflicting-lifecycle": true,
"no-host-metadata-property": true, "no-host-metadata-property": true,
"no-input-rename": true, "no-input-rename": true,

View File

@ -1,31 +1,61 @@
{ {
"extends": "tslint:recommended",
"rules": { "rules": {
"class-name": true, "align": {
"comment-format": [ "options": [
true, "parameters",
"check-space" "statements"
], ]
},
"array-type": false,
"arrow-return-shorthand": true,
"curly": true, "curly": true,
"eofline": true, "deprecation": {
"forin": true, "severity": "warning"
"indent": [ },
"component-class-suffix": true,
"component-selector": [
true, true,
"spaces" "element",
// TODO: Fix the code and change the prefix to `"app"` (or whatever makes sense).
"",
"kebab-case"
], ],
"label-position": true, "contextual-lifecycle": true,
"label-undefined": true, "directive-class-suffix": true,
"directive-selector": [
true,
"attribute",
["app", "toh"],
"camelCase"
],
"eofline": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false,
"max-line-length": [ "max-line-length": [
true, true,
140 140
], ],
"member-access": false,
"member-ordering": [ "member-ordering": [
true, true,
"static-before-instance", {
"variables-before-functions" "order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
], ],
"no-arg": true,
"no-bitwise": true,
"no-console": [ "no-console": [
true, true,
"debug", "debug",
@ -34,59 +64,86 @@
"timeEnd", "timeEnd",
"trace" "trace"
], ],
"no-construct": true,
"no-debugger": true,
"no-duplicate-key": true,
"no-duplicate-variable": true,
"no-empty": false, "no-empty": false,
"no-eval": true, "no-inferrable-types": [
"no-inferrable-types": true,
"no-shadowed-variable": true,
"no-string-literal": false,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-unused-variable": true,
"no-unreachable": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true, true,
"check-open-brace", "ignore-params"
"check-catch", ],
"check-else", "no-non-null-assertion": true,
"check-whitespace" "no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
], ],
"quotemark": [ "quotemark": [
true, true,
"single" "single"
], ],
"radix": true, "semicolon": {
"semicolon": [ "options": [
"always" "always"
], ]
"triple-equals": [ },
true, "space-before-function-paren": {
"allow-null-check" "options": {
], "anonymous": "never",
"typedef-whitespace": [ "asyncArrow": "always",
true, "constructor": "never",
{ "method": "never",
"call-signature": "nospace", "named": "never"
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
} }
], },
"variable-name": false, "typedef-whitespace": {
"whitespace": [ "options": [
true, {
"check-branch", "call-signature": "nospace",
"check-decl", "index-signature": "nospace",
"check-operator", "parameter": "nospace",
"check-separator", "property-declaration": "nospace",
"check-type" "variable-declaration": "nospace"
] },
} {
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-pascal-case"
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
},
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-inputs-metadata-property": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-outputs-metadata-property": true,
"template-banana-in-box": true,
"template-no-negated-async": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true
},
"rulesDirectory": [
"codelyzer"
]
} }