From 1db4f508e6581a63bc7725ba79be4296bf9516bc Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 30 Jul 2020 13:03:16 +0300 Subject: [PATCH] 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 --- .../src/app/app.module.ts | 12 ++++++------ .../src/app/providers.component.ts | 4 ++-- .../examples/event-binding/e2e/src/app.e2e-spec.ts | 3 +-- .../examples/http/src/app/request-cache.service.ts | 4 ++-- .../examples/http/src/testing/http-client.spec.ts | 2 +- .../examples/inputs-outputs/e2e/src/app.e2e-spec.ts | 11 +++-------- aio/content/examples/observables/src/multicasting.ts | 6 +++--- .../e2e/src/app.e2e-spec.ts | 11 +++-------- .../hero/hero-detail.component.no-testbed.spec.ts | 2 -- .../src/app/hero/hero-detail.component.spec.ts | 6 +++--- .../src/app/model/testing/http-client.spec.ts | 2 +- aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts | 6 +++--- .../app/phone-detail/phone-detail.component.ts | 6 +++--- 13 files changed, 31 insertions(+), 44 deletions(-) diff --git a/aio/content/examples/dependency-injection-in-action/src/app/app.module.ts b/aio/content/examples/dependency-injection-in-action/src/app/app.module.ts index 93926580c2..a2d57cb659 100644 --- a/aio/content/examples/dependency-injection-in-action/src/app/app.module.ts +++ b/aio/content/examples/dependency-injection-in-action/src/app/app.module.ts @@ -42,11 +42,11 @@ const declarations = [ 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, CathyComponent ]; @@ -61,9 +61,9 @@ const c_components = [ ], declarations: [ declarations, - a_components, - b_components, - c_components, + componentListA, + componentListB, + componentListC, StorageComponent, ], bootstrap: [ AppComponent ], diff --git a/aio/content/examples/dependency-injection/src/app/providers.component.ts b/aio/content/examples/dependency-injection/src/app/providers.component.ts index dcad19b77c..e6a98917fb 100644 --- a/aio/content/examples/dependency-injection/src/app/providers.component.ts +++ b/aio/content/examples/dependency-injection/src/app/providers.component.ts @@ -237,7 +237,7 @@ export class Provider9Component implements OnInit { import { Optional } from '@angular/core'; // #enddocregion import-optional -let some_message = 'Hello from the injected logger'; +let someMessage = 'Hello from the injected logger'; @Component({ selector: 'provider-10', @@ -249,7 +249,7 @@ export class Provider10Component implements OnInit { // #docregion provider-10-ctor constructor(@Optional() private logger?: Logger) { if (this.logger) { - this.logger.log(some_message); + this.logger.log(someMessage); } } // #enddocregion provider-10-ctor diff --git a/aio/content/examples/event-binding/e2e/src/app.e2e-spec.ts b/aio/content/examples/event-binding/e2e/src/app.e2e-spec.ts index ea5f3eb324..5731d319d1 100644 --- a/aio/content/examples/event-binding/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/event-binding/e2e/src/app.e2e-spec.ts @@ -1,4 +1,4 @@ -import { browser, element, by, protractor } from 'protractor'; +import { browser, element, by } from 'protractor'; describe('Event binding example', () => { @@ -36,7 +36,6 @@ describe('Event binding example', () => { }); it('should hide the item img', async () => { - let deleteButton = element.all(by.css('button')).get(3); await deleteButton.click(); browser.switchTo().alert().accept(); expect(element.all(by.css('img')).get(0).getCssValue('display')).toEqual('none'); diff --git a/aio/content/examples/http/src/app/request-cache.service.ts b/aio/content/examples/http/src/app/request-cache.service.ts index aeb2ff9662..9e3fbc83b5 100644 --- a/aio/content/examples/http/src/app/request-cache.service.ts +++ b/aio/content/examples/http/src/app/request-cache.service.ts @@ -44,8 +44,8 @@ export class RequestCacheWithMap implements RequestCache { const url = req.urlWithParams; this.messenger.add(`Caching response from "${url}".`); - const entry = { url, response, lastRead: Date.now() }; - this.cache.set(url, entry); + const newEntry = { url, response, lastRead: Date.now() }; + this.cache.set(url, newEntry); // remove expired cache entries const expired = Date.now() - maxAge; diff --git a/aio/content/examples/http/src/testing/http-client.spec.ts b/aio/content/examples/http/src/testing/http-client.spec.ts index e014cec674..047f29b4fe 100644 --- a/aio/content/examples/http/src/testing/http-client.spec.ts +++ b/aio/content/examples/http/src/testing/http-client.spec.ts @@ -83,7 +83,7 @@ describe('HttpClient testing', () => { // #docregion predicate // Expect one request with an authorization header const req = httpTestingController.expectOne( - req => req.headers.has('Authorization') + request => request.headers.has('Authorization') ); // #enddocregion predicate req.flush(testData); diff --git a/aio/content/examples/inputs-outputs/e2e/src/app.e2e-spec.ts b/aio/content/examples/inputs-outputs/e2e/src/app.e2e-spec.ts index 225fea8bb7..145e42bab7 100644 --- a/aio/content/examples/inputs-outputs/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/inputs-outputs/e2e/src/app.e2e-spec.ts @@ -4,9 +4,7 @@ import { logging } from 'selenium-webdriver'; describe('Inputs and Outputs', () => { - beforeEach(() => { - browser.get(''); - }); + beforeEach(() => browser.get('')); // helper function used to test what's logged to the console @@ -15,11 +13,8 @@ describe('Inputs and Outputs', () => { .manage() .logs() .get(logging.Type.BROWSER); - const message = logs.filter(({ message }) => - message.indexOf(contents) !== -1 ? true : false - ); - console.log(message); - expect(message.length).toBeGreaterThan(0); + const messages = logs.filter(({ message }) => message.indexOf(contents) !== -1); + expect(messages.length).toBeGreaterThan(0); } it('should have title Inputs and Outputs', () => { diff --git a/aio/content/examples/observables/src/multicasting.ts b/aio/content/examples/observables/src/multicasting.ts index e8275842f0..2d622e41ff 100644 --- a/aio/content/examples/observables/src/multicasting.ts +++ b/aio/content/examples/observables/src/multicasting.ts @@ -9,18 +9,18 @@ function sequenceSubscriber(observer) { // Will run through an array of numbers, emitting one value // per second until it gets to the end of the array. - function doSequence(arr, idx) { + function doInSequence(arr, idx) { timeoutId = setTimeout(() => { observer.next(arr[idx]); if (idx === arr.length - 1) { observer.complete(); } else { - doSequence(arr, ++idx); + doInSequence(arr, ++idx); } }, 1000); } - doSequence(seq, 0); + doInSequence(seq, 0); // Unsubscribe should clear the timeout to stop execution return {unsubscribe() { diff --git a/aio/content/examples/template-reference-variables/e2e/src/app.e2e-spec.ts b/aio/content/examples/template-reference-variables/e2e/src/app.e2e-spec.ts index 08ab644a61..3eefa04e5f 100644 --- a/aio/content/examples/template-reference-variables/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/template-reference-variables/e2e/src/app.e2e-spec.ts @@ -2,10 +2,7 @@ import { browser, element, by } from 'protractor'; import { logging } from 'selenium-webdriver'; describe('Template-reference-variables-example', () => { - beforeEach(() => { - browser.get(''); - - }); + beforeEach(() => browser.get('')); // helper function used to test what's logged to the console async function logChecker(button, contents) { @@ -13,10 +10,8 @@ describe('Template-reference-variables-example', () => { .manage() .logs() .get(logging.Type.BROWSER); - const message = logs.filter(({ message }) => - message.indexOf(contents) !== -1 ? true : false - ); - expect(message.length).toBeGreaterThan(0); + const messages = logs.filter(({ message }) => message.indexOf(contents) !== -1); + expect(messages.length).toBeGreaterThan(0); } it('should display Template reference variables', () => { diff --git a/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts b/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts index 51e65e65bb..e9bacab155 100644 --- a/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts +++ b/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts @@ -6,7 +6,6 @@ import { Hero } from '../model/hero'; ////////// Tests //////////////////// describe('HeroDetailComponent - no TestBed', () => { - let activatedRoute: ActivatedRouteStub; let comp: HeroDetailComponent; let expectedHero: Hero; let hds: any; @@ -26,7 +25,6 @@ describe('HeroDetailComponent - no TestBed', () => { // OnInit calls HDS.getHero; wait for it to get the fake hero hds.getHero.calls.first().returnValue.subscribe(done); - }); it('should expose the hero retrieved from the service', () => { diff --git a/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts b/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts index 0d0c4af9e9..9fc287d137 100644 --- a/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts +++ b/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts @@ -356,14 +356,14 @@ class Page { gotoListSpy: jasmine.Spy; navigateSpy: jasmine.Spy; - constructor(fixture: ComponentFixture) { + constructor(someFixture: ComponentFixture) { // get the navigate spy from the injected router spy object const routerSpy = someFixture.debugElement.injector.get(Router) as any; this.navigateSpy = routerSpy.navigate; // spy on component's `gotoList()` method - const component = fixture.componentInstance; - this.gotoListSpy = spyOn(component, 'gotoList').and.callThrough(); + const someComponent = someFixture.componentInstance; + this.gotoListSpy = spyOn(someComponent, 'gotoList').and.callThrough(); } //// query helpers //// diff --git a/aio/content/examples/testing/src/app/model/testing/http-client.spec.ts b/aio/content/examples/testing/src/app/model/testing/http-client.spec.ts index d6a1dac882..abb4f996d8 100644 --- a/aio/content/examples/testing/src/app/model/testing/http-client.spec.ts +++ b/aio/content/examples/testing/src/app/model/testing/http-client.spec.ts @@ -82,7 +82,7 @@ describe('HttpClient testing', () => { // #docregion predicate // Expect one request with an authorization header const req = httpTestingController.expectOne( - req => req.headers.has('Authorization') + request => request.headers.has('Authorization') ); // #enddocregion predicate req.flush(testData); diff --git a/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts b/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts index 2f8b82a13b..8cc6517b30 100644 --- a/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts @@ -172,11 +172,11 @@ describe('Tutorial part 6', () => { }); it(`adds back ${targetHero.name}`, async () => { - const newHeroName = 'Alice'; + const addedHeroName = 'Alice'; const heroesBefore = await toHeroArray(getPageElts().allHeroes); const numHeroes = heroesBefore.length; - element(by.css('input')).sendKeys(newHeroName); + element(by.css('input')).sendKeys(addedHeroName); element(by.buttonText('add')).click(); let page = getPageElts(); @@ -186,7 +186,7 @@ describe('Tutorial part 6', () => { expect(heroesAfter.slice(0, numHeroes)).toEqual(heroesBefore, 'Old heroes are still there'); 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 () => { diff --git a/aio/content/examples/upgrade-phonecat-2-hybrid/app/phone-detail/phone-detail.component.ts b/aio/content/examples/upgrade-phonecat-2-hybrid/app/phone-detail/phone-detail.component.ts index 48c2dc7f00..4483f682d2 100644 --- a/aio/content/examples/upgrade-phonecat-2-hybrid/app/phone-detail/phone-detail.component.ts +++ b/aio/content/examples/upgrade-phonecat-2-hybrid/app/phone-detail/phone-detail.component.ts @@ -22,9 +22,9 @@ export class PhoneDetailComponent { mainImageUrl: string; constructor(routeParams: RouteParams, phone: Phone) { - phone.get(routeParams.phoneId).subscribe(phone => { - this.phone = phone; - this.setImage(phone.images[0]); + phone.get(routeParams.phoneId).subscribe(data => { + this.phone = data; + this.setImage(data.images[0]); }); }