refactor(docs-infra): fix docs examples for tslint rules related to variable names (#38143)

This commit updates the docs examples to be compatible with the
`no-shadowed-variable` and `variable-name` tslint rules.

This is in preparation of updating the docs examples `tslint.json` to
match the one generated for new Angular CLI apps in a future commit.

PR Close #38143
This commit is contained in:
George Kalpakas 2020-07-30 13:03:16 +03:00 committed by Alex Rickabaugh
parent 6334749d2c
commit 1db4f508e6
13 changed files with 31 additions and 44 deletions

View File

@ -42,11 +42,11 @@ const declarations = [
ParentFinderComponent, ParentFinderComponent,
]; ];
const a_components = [AliceComponent, AlexComponent ]; const componentListA = [ AliceComponent, AlexComponent ];
const b_components = [ BarryComponent, BethComponent, BobComponent ]; const componentListB = [ BarryComponent, BethComponent, BobComponent ];
const c_components = [ const componentListC = [
CarolComponent, ChrisComponent, CraigComponent, CarolComponent, ChrisComponent, CraigComponent,
CathyComponent CathyComponent
]; ];
@ -61,9 +61,9 @@ const c_components = [
], ],
declarations: [ declarations: [
declarations, declarations,
a_components, componentListA,
b_components, componentListB,
c_components, componentListC,
StorageComponent, StorageComponent,
], ],
bootstrap: [ AppComponent ], bootstrap: [ AppComponent ],

View File

@ -237,7 +237,7 @@ export class Provider9Component implements OnInit {
import { Optional } from '@angular/core'; import { Optional } from '@angular/core';
// #enddocregion import-optional // #enddocregion import-optional
let some_message = 'Hello from the injected logger'; let someMessage = 'Hello from the injected logger';
@Component({ @Component({
selector: 'provider-10', selector: 'provider-10',
@ -249,7 +249,7 @@ export class Provider10Component implements OnInit {
// #docregion provider-10-ctor // #docregion provider-10-ctor
constructor(@Optional() private logger?: Logger) { constructor(@Optional() private logger?: Logger) {
if (this.logger) { if (this.logger) {
this.logger.log(some_message); this.logger.log(someMessage);
} }
} }
// #enddocregion provider-10-ctor // #enddocregion provider-10-ctor

View File

@ -1,4 +1,4 @@
import { browser, element, by, protractor } from 'protractor'; import { browser, element, by } from 'protractor';
describe('Event binding example', () => { describe('Event binding example', () => {
@ -36,7 +36,6 @@ describe('Event binding example', () => {
}); });
it('should hide the item img', async () => { it('should hide the item img', async () => {
let deleteButton = element.all(by.css('button')).get(3);
await deleteButton.click(); await deleteButton.click();
browser.switchTo().alert().accept(); browser.switchTo().alert().accept();
expect(element.all(by.css('img')).get(0).getCssValue('display')).toEqual('none'); expect(element.all(by.css('img')).get(0).getCssValue('display')).toEqual('none');

View File

@ -44,8 +44,8 @@ export class RequestCacheWithMap implements RequestCache {
const url = req.urlWithParams; const url = req.urlWithParams;
this.messenger.add(`Caching response from "${url}".`); this.messenger.add(`Caching response from "${url}".`);
const entry = { url, response, lastRead: Date.now() }; const newEntry = { url, response, lastRead: Date.now() };
this.cache.set(url, entry); this.cache.set(url, newEntry);
// remove expired cache entries // remove expired cache entries
const expired = Date.now() - maxAge; const expired = Date.now() - maxAge;

View File

@ -83,7 +83,7 @@ describe('HttpClient testing', () => {
// #docregion predicate // #docregion predicate
// Expect one request with an authorization header // Expect one request with an authorization header
const req = httpTestingController.expectOne( const req = httpTestingController.expectOne(
req => req.headers.has('Authorization') request => request.headers.has('Authorization')
); );
// #enddocregion predicate // #enddocregion predicate
req.flush(testData); req.flush(testData);

View File

@ -4,9 +4,7 @@ import { logging } from 'selenium-webdriver';
describe('Inputs and Outputs', () => { describe('Inputs and Outputs', () => {
beforeEach(() => { beforeEach(() => browser.get(''));
browser.get('');
});
// helper function used to test what's logged to the console // helper function used to test what's logged to the console
@ -15,11 +13,8 @@ describe('Inputs and Outputs', () => {
.manage() .manage()
.logs() .logs()
.get(logging.Type.BROWSER); .get(logging.Type.BROWSER);
const message = logs.filter(({ message }) => const messages = logs.filter(({ message }) => message.indexOf(contents) !== -1);
message.indexOf(contents) !== -1 ? true : false expect(messages.length).toBeGreaterThan(0);
);
console.log(message);
expect(message.length).toBeGreaterThan(0);
} }
it('should have title Inputs and Outputs', () => { it('should have title Inputs and Outputs', () => {

View File

@ -9,18 +9,18 @@ function sequenceSubscriber(observer) {
// Will run through an array of numbers, emitting one value // Will run through an array of numbers, emitting one value
// per second until it gets to the end of the array. // per second until it gets to the end of the array.
function doSequence(arr, idx) { function doInSequence(arr, idx) {
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {
observer.next(arr[idx]); observer.next(arr[idx]);
if (idx === arr.length - 1) { if (idx === arr.length - 1) {
observer.complete(); observer.complete();
} else { } else {
doSequence(arr, ++idx); doInSequence(arr, ++idx);
} }
}, 1000); }, 1000);
} }
doSequence(seq, 0); doInSequence(seq, 0);
// Unsubscribe should clear the timeout to stop execution // Unsubscribe should clear the timeout to stop execution
return {unsubscribe() { return {unsubscribe() {

View File

@ -2,10 +2,7 @@ import { browser, element, by } from 'protractor';
import { logging } from 'selenium-webdriver'; import { logging } from 'selenium-webdriver';
describe('Template-reference-variables-example', () => { describe('Template-reference-variables-example', () => {
beforeEach(() => { beforeEach(() => browser.get(''));
browser.get('');
});
// helper function used to test what's logged to the console // helper function used to test what's logged to the console
async function logChecker(button, contents) { async function logChecker(button, contents) {
@ -13,10 +10,8 @@ describe('Template-reference-variables-example', () => {
.manage() .manage()
.logs() .logs()
.get(logging.Type.BROWSER); .get(logging.Type.BROWSER);
const message = logs.filter(({ message }) => const messages = logs.filter(({ message }) => message.indexOf(contents) !== -1);
message.indexOf(contents) !== -1 ? true : false expect(messages.length).toBeGreaterThan(0);
);
expect(message.length).toBeGreaterThan(0);
} }
it('should display Template reference variables', () => { it('should display Template reference variables', () => {

View File

@ -6,7 +6,6 @@ import { Hero } from '../model/hero';
////////// Tests //////////////////// ////////// Tests ////////////////////
describe('HeroDetailComponent - no TestBed', () => { describe('HeroDetailComponent - no TestBed', () => {
let activatedRoute: ActivatedRouteStub;
let comp: HeroDetailComponent; let comp: HeroDetailComponent;
let expectedHero: Hero; let expectedHero: Hero;
let hds: any; let hds: any;
@ -26,7 +25,6 @@ describe('HeroDetailComponent - no TestBed', () => {
// OnInit calls HDS.getHero; wait for it to get the fake hero // OnInit calls HDS.getHero; wait for it to get the fake hero
hds.getHero.calls.first().returnValue.subscribe(done); hds.getHero.calls.first().returnValue.subscribe(done);
}); });
it('should expose the hero retrieved from the service', () => { it('should expose the hero retrieved from the service', () => {

View File

@ -356,14 +356,14 @@ class Page {
gotoListSpy: jasmine.Spy; gotoListSpy: jasmine.Spy;
navigateSpy: jasmine.Spy; navigateSpy: jasmine.Spy;
constructor(fixture: ComponentFixture<HeroDetailComponent>) { constructor(someFixture: ComponentFixture<HeroDetailComponent>) {
// get the navigate spy from the injected router spy object // get the navigate spy from the injected router spy object
const routerSpy = someFixture.debugElement.injector.get(Router) as any; const routerSpy = someFixture.debugElement.injector.get(Router) as any;
this.navigateSpy = routerSpy.navigate; this.navigateSpy = routerSpy.navigate;
// spy on component's `gotoList()` method // spy on component's `gotoList()` method
const component = fixture.componentInstance; const someComponent = someFixture.componentInstance;
this.gotoListSpy = spyOn(component, 'gotoList').and.callThrough(); this.gotoListSpy = spyOn(someComponent, 'gotoList').and.callThrough();
} }
//// query helpers //// //// query helpers ////

View File

@ -82,7 +82,7 @@ describe('HttpClient testing', () => {
// #docregion predicate // #docregion predicate
// Expect one request with an authorization header // Expect one request with an authorization header
const req = httpTestingController.expectOne( const req = httpTestingController.expectOne(
req => req.headers.has('Authorization') request => request.headers.has('Authorization')
); );
// #enddocregion predicate // #enddocregion predicate
req.flush(testData); req.flush(testData);

View File

@ -172,11 +172,11 @@ describe('Tutorial part 6', () => {
}); });
it(`adds back ${targetHero.name}`, async () => { it(`adds back ${targetHero.name}`, async () => {
const newHeroName = 'Alice'; const addedHeroName = 'Alice';
const heroesBefore = await toHeroArray(getPageElts().allHeroes); const heroesBefore = await toHeroArray(getPageElts().allHeroes);
const numHeroes = heroesBefore.length; const numHeroes = heroesBefore.length;
element(by.css('input')).sendKeys(newHeroName); element(by.css('input')).sendKeys(addedHeroName);
element(by.buttonText('add')).click(); element(by.buttonText('add')).click();
let page = getPageElts(); let page = getPageElts();
@ -186,7 +186,7 @@ describe('Tutorial part 6', () => {
expect(heroesAfter.slice(0, numHeroes)).toEqual(heroesBefore, 'Old heroes are still there'); expect(heroesAfter.slice(0, numHeroes)).toEqual(heroesBefore, 'Old heroes are still there');
const maxId = heroesBefore[heroesBefore.length - 1].id; const maxId = heroesBefore[heroesBefore.length - 1].id;
expect(heroesAfter[numHeroes]).toEqual({id: maxId + 1, name: newHeroName}); expect(heroesAfter[numHeroes]).toEqual({id: maxId + 1, name: addedHeroName});
}); });
it('displays correctly styled buttons', async () => { it('displays correctly styled buttons', async () => {

View File

@ -22,9 +22,9 @@ export class PhoneDetailComponent {
mainImageUrl: string; mainImageUrl: string;
constructor(routeParams: RouteParams, phone: Phone) { constructor(routeParams: RouteParams, phone: Phone) {
phone.get(routeParams.phoneId).subscribe(phone => { phone.get(routeParams.phoneId).subscribe(data => {
this.phone = phone; this.phone = data;
this.setImage(phone.images[0]); this.setImage(data.images[0]);
}); });
} }