From ba11f7b90b92ddcdbccd48d7ce143bb461f94cab Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 30 Jul 2020 13:03:17 +0300 Subject: [PATCH] refactor(docs-infra): fix docs examples for tslint rules related to underscores in variable names (#38143) This commit updates the docs examples to be compatible with the `variable-name` tslint rule without requiring the `allow-leading-underscore` and `allow-trailing-underscore` options. 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/hero-list-page.component.ts | 8 ++--- .../architecture/e2e/src/app.e2e-spec.ts | 10 +++---- .../e2e/src/app.e2e-spec.ts | 6 ++-- .../e2e/src/app.e2e-spec.ts | 30 +++++++++---------- .../src/app/name-child.component.ts | 7 ++--- .../displaying-data/e2e/src/app.e2e-spec.ts | 12 ++++---- .../docs-style-guide/e2e/src/app.e2e-spec.ts | 6 ++-- .../elements/src/app/popup.component.ts | 6 ++-- .../src/app/greeting/user.service.ts | 2 +- .../my-lib/schematics/ng-add/index.ts | 6 ++-- .../src/app/app.component.ts | 7 ++--- .../examples/toh-pt1/e2e/src/app.e2e-spec.ts | 8 ++--- .../examples/toh-pt2/e2e/src/app.e2e-spec.ts | 8 ++--- .../examples/toh-pt3/e2e/src/app.e2e-spec.ts | 8 ++--- .../examples/toh-pt4/e2e/src/app.e2e-spec.ts | 8 ++--- .../examples/toh-pt5/e2e/src/app.e2e-spec.ts | 8 ++--- .../examples/toh-pt6/e2e/src/app.e2e-spec.ts | 8 ++--- .../app/core/phone/phone.service.spec.ts | 1 + .../phone-detail.component.spec.ts | 1 + .../phone-list/phone-list.component.spec.ts | 1 + .../app/core/phone/phone.service.spec.ts | 1 + .../app/core/phone/phone.service.spec.ts | 1 + 22 files changed, 77 insertions(+), 76 deletions(-) diff --git a/aio/content/examples/animations/src/app/hero-list-page.component.ts b/aio/content/examples/animations/src/app/hero-list-page.component.ts index 746c195d19..0963f5d8e2 100644 --- a/aio/content/examples/animations/src/app/hero-list-page.component.ts +++ b/aio/content/examples/animations/src/app/hero-list-page.component.ts @@ -1,4 +1,6 @@ +// tslint:disable: variable-name // #docplaster +// #docregion import { Component, HostBinding, OnInit } from '@angular/core'; import { trigger, transition, animate, style, query, stagger } from '@angular/animations'; import { HEROES } from './mock-heroes'; @@ -52,13 +54,11 @@ export class HeroListPageComponent implements OnInit { @HostBinding('@pageAnimations') public animatePage = true; - _heroes = []; // #docregion filter-animations heroTotal = -1; // #enddocregion filter-animations - get heroes() { - return this._heroes; - } + get heroes() { return this._heroes; } + private _heroes = []; ngOnInit() { this._heroes = HEROES; diff --git a/aio/content/examples/architecture/e2e/src/app.e2e-spec.ts b/aio/content/examples/architecture/e2e/src/app.e2e-spec.ts index b5084ab9a1..8dd1f50543 100644 --- a/aio/content/examples/architecture/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/architecture/e2e/src/app.e2e-spec.ts @@ -86,13 +86,11 @@ function getPageElts() { async function heroFromDetail(detail: ElementFinder): Promise { // Get hero id from the first
- // let _id = await detail.all(by.css('div')).first().getText(); - let _id = await detail.all(by.css('div')).first().getText(); + let id = await detail.all(by.css('div')).first().getText(); // Get name from the h2 - // let _name = await detail.element(by.css('h4')).getText(); - let _name = await detail.element(by.css('h4')).getText(); + let name = await detail.element(by.css('h4')).getText(); return { - id: +_id.substr(_id.indexOf(' ') + 1), - name: _name.substr(0, _name.lastIndexOf(' ')) + id: +id.substr(id.indexOf(' ') + 1), + name: name.substr(0, name.lastIndexOf(' ')), }; } diff --git a/aio/content/examples/attribute-directives/e2e/src/app.e2e-spec.ts b/aio/content/examples/attribute-directives/e2e/src/app.e2e-spec.ts index 855a48af38..3fc012b855 100644 --- a/aio/content/examples/attribute-directives/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/attribute-directives/e2e/src/app.e2e-spec.ts @@ -2,14 +2,14 @@ import { browser, element, by } from 'protractor'; describe('Attribute directives', () => { - let _title = 'My First Attribute Directive'; + let title = 'My First Attribute Directive'; beforeAll(() => { browser.get(''); }); - it(`should display correct title: ${_title}`, () => { - expect(element(by.css('h1')).getText()).toEqual(_title); + it(`should display correct title: ${title}`, () => { + expect(element(by.css('h1')).getText()).toEqual(title); }); it('should be able to select green highlight', () => { diff --git a/aio/content/examples/component-interaction/e2e/src/app.e2e-spec.ts b/aio/content/examples/component-interaction/e2e/src/app.e2e-spec.ts index 10a4120200..8f0503d04c 100644 --- a/aio/content/examples/component-interaction/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/component-interaction/e2e/src/app.e2e-spec.ts @@ -11,18 +11,18 @@ describe('Component Communication Cookbook Tests', () => { describe('Parent-to-child communication', () => { // #docregion parent-to-child // ... - let _heroNames = ['Dr IQ', 'Magneta', 'Bombasto']; - let _masterName = 'Master'; + let heroNames = ['Dr IQ', 'Magneta', 'Bombasto']; + let masterName = 'Master'; it('should pass properties to children properly', () => { let parent = element.all(by.tagName('app-hero-parent')).get(0); let heroes = parent.all(by.tagName('app-hero-child')); - for (let i = 0; i < _heroNames.length; i++) { + for (let i = 0; i < heroNames.length; i++) { let childTitle = heroes.get(i).element(by.tagName('h3')).getText(); let childDetail = heroes.get(i).element(by.tagName('p')).getText(); - expect(childTitle).toEqual(_heroNames[i] + ' says:'); - expect(childDetail).toContain(_masterName); + expect(childTitle).toEqual(heroNames[i] + ' says:'); + expect(childDetail).toContain(masterName); } }); // ... @@ -33,23 +33,23 @@ describe('Component Communication Cookbook Tests', () => { // #docregion parent-to-child-setter // ... it('should display trimmed, non-empty names', () => { - let _nonEmptyNameIndex = 0; - let _nonEmptyName = '"Dr IQ"'; + let nonEmptyNameIndex = 0; + let nonEmptyName = '"Dr IQ"'; let parent = element.all(by.tagName('app-name-parent')).get(0); - let hero = parent.all(by.tagName('app-name-child')).get(_nonEmptyNameIndex); + let hero = parent.all(by.tagName('app-name-child')).get(nonEmptyNameIndex); let displayName = hero.element(by.tagName('h3')).getText(); - expect(displayName).toEqual(_nonEmptyName); + expect(displayName).toEqual(nonEmptyName); }); it('should replace empty name with default name', () => { - let _emptyNameIndex = 1; - let _defaultName = '""'; + let emptyNameIndex = 1; + let defaultName = '""'; let parent = element.all(by.tagName('app-name-parent')).get(0); - let hero = parent.all(by.tagName('app-name-child')).get(_emptyNameIndex); + let hero = parent.all(by.tagName('app-name-child')).get(emptyNameIndex); let displayName = hero.element(by.tagName('h3')).getText(); - expect(displayName).toEqual(_defaultName); + expect(displayName).toEqual(defaultName); }); // ... // #enddocregion parent-to-child-setter @@ -214,13 +214,13 @@ describe('Component Communication Cookbook Tests', () => { }); function testConfirmMission(buttonIndex: number, expectedLogCount: number, astronaut: string) { - let _confirmedLog = ' confirmed the mission'; + let confirmedLog = ' confirmed the mission'; let missionControl = element(by.tagName('app-mission-control')); let confirmButton = missionControl.all(by.tagName('button')).get(buttonIndex); confirmButton.click().then(() => { let history = missionControl.all(by.tagName('li')); expect(history.count()).toBe(expectedLogCount); - expect(history.get(expectedLogCount - 1).getText()).toBe(astronaut + _confirmedLog); + expect(history.get(expectedLogCount - 1).getText()).toBe(astronaut + confirmedLog); }); } // ... diff --git a/aio/content/examples/component-interaction/src/app/name-child.component.ts b/aio/content/examples/component-interaction/src/app/name-child.component.ts index 8393e21ebd..06e65bb87c 100644 --- a/aio/content/examples/component-interaction/src/app/name-child.component.ts +++ b/aio/content/examples/component-interaction/src/app/name-child.component.ts @@ -1,3 +1,4 @@ +// tslint:disable: variable-name // #docregion import { Component, Input } from '@angular/core'; @@ -6,13 +7,11 @@ import { Component, Input } from '@angular/core'; template: '

"{{name}}"

' }) export class NameChildComponent { - private _name = ''; - @Input() + get name(): string { return this._name; } set name(name: string) { this._name = (name && name.trim()) || ''; } - - get name(): string { return this._name; } + private _name = ''; } // #enddocregion diff --git a/aio/content/examples/displaying-data/e2e/src/app.e2e-spec.ts b/aio/content/examples/displaying-data/e2e/src/app.e2e-spec.ts index 8044590cf5..e95a657eb0 100644 --- a/aio/content/examples/displaying-data/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/displaying-data/e2e/src/app.e2e-spec.ts @@ -1,19 +1,19 @@ import { browser, element, by } from 'protractor'; describe('Displaying Data Tests', () => { - let _title = 'Tour of Heroes'; - let _defaultHero = 'Windstorm'; + let title = 'Tour of Heroes'; + let defaultHero = 'Windstorm'; beforeAll(() => { browser.get(''); }); - it('should display correct title: ' + _title, () => { - expect(element(by.css('h1')).getText()).toEqual(_title); + it('should display correct title: ' + title, () => { + expect(element(by.css('h1')).getText()).toEqual(title); }); - it('should have correct default hero: ' + _defaultHero, () => { - expect(element(by.css('h2')).getText()).toContain(_defaultHero); + it('should have correct default hero: ' + defaultHero, () => { + expect(element(by.css('h2')).getText()).toContain(defaultHero); }); it('should have heroes', () => { diff --git a/aio/content/examples/docs-style-guide/e2e/src/app.e2e-spec.ts b/aio/content/examples/docs-style-guide/e2e/src/app.e2e-spec.ts index 27f24851c3..cbcb0c7dbc 100644 --- a/aio/content/examples/docs-style-guide/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/docs-style-guide/e2e/src/app.e2e-spec.ts @@ -1,13 +1,13 @@ import { browser, element, by } from 'protractor'; describe('Docs Style Guide', () => { - let _title = 'Authors Style Guide Sample'; + let title = 'Authors Style Guide Sample'; beforeAll(() => { browser.get(''); }); - it('should display correct title: ' + _title, () => { - expect(element(by.css('h1')).getText()).toEqual(_title); + it('should display correct title: ' + title, () => { + expect(element(by.css('h1')).getText()).toEqual(title); }); }); diff --git a/aio/content/examples/elements/src/app/popup.component.ts b/aio/content/examples/elements/src/app/popup.component.ts index cc663a1b8f..a2383ba69a 100644 --- a/aio/content/examples/elements/src/app/popup.component.ts +++ b/aio/content/examples/elements/src/app/popup.component.ts @@ -1,3 +1,5 @@ +// tslint:disable: variable-name +// #docregion import { Component, EventEmitter, Input, Output } from '@angular/core'; import { animate, state, style, transition, trigger } from '@angular/animations'; @@ -42,12 +44,12 @@ export class PopupComponent { state: 'opened' | 'closed' = 'closed'; @Input() + get message(): string { return this._message; } set message(message: string) { this._message = message; this.state = 'opened'; } - get message(): string { return this._message; } - _message: string; + private _message: string; @Output() closed = new EventEmitter(); diff --git a/aio/content/examples/ngmodules/src/app/greeting/user.service.ts b/aio/content/examples/ngmodules/src/app/greeting/user.service.ts index 3908e85a3c..d084d1b099 100644 --- a/aio/content/examples/ngmodules/src/app/greeting/user.service.ts +++ b/aio/content/examples/ngmodules/src/app/greeting/user.service.ts @@ -12,7 +12,6 @@ export class UserServiceConfig { }) export class UserService { id = nextId++; - private _userName = 'Sherlock Holmes'; // #docregion ctor constructor(@Optional() config?: UserServiceConfig) { @@ -25,4 +24,5 @@ export class UserService { const suffix = this.id > 1 ? ` times ${this.id}` : ''; return this._userName + suffix; } + private _userName = 'Sherlock Holmes'; // tslint:disable-line: variable-name } diff --git a/aio/content/examples/schematics-for-libraries/projects/my-lib/schematics/ng-add/index.ts b/aio/content/examples/schematics-for-libraries/projects/my-lib/schematics/ng-add/index.ts index f749c7a61f..f56ff2ba1d 100644 --- a/aio/content/examples/schematics-for-libraries/projects/my-lib/schematics/ng-add/index.ts +++ b/aio/content/examples/schematics-for-libraries/projects/my-lib/schematics/ng-add/index.ts @@ -2,9 +2,9 @@ import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; // Just return the tree -export function ngAdd(_options: any): Rule { - return (tree: Tree, _context: SchematicContext) => { - _context.addTask(new NodePackageInstallTask()); +export function ngAdd(options: any): Rule { + return (tree: Tree, context: SchematicContext) => { + context.addTask(new NodePackageInstallTask()); return tree; }; } diff --git a/aio/content/examples/template-reference-variables/src/app/app.component.ts b/aio/content/examples/template-reference-variables/src/app/app.component.ts index 706ccea85f..ad3a21366c 100644 --- a/aio/content/examples/template-reference-variables/src/app/app.component.ts +++ b/aio/content/examples/template-reference-variables/src/app/app.component.ts @@ -10,11 +10,8 @@ import { NgForm } from '@angular/forms'; export class AppComponent { @ViewChild('itemForm') form: NgForm; - private _submitMessage = ''; - - get submitMessage() { - return this._submitMessage; - } + get submitMessage() { return this._submitMessage; } + private _submitMessage = ''; // tslint:disable-line: variable-name onSubmit(form: NgForm) { this._submitMessage = 'Submitted. Form value is ' + JSON.stringify(form.value); diff --git a/aio/content/examples/toh-pt1/e2e/src/app.e2e-spec.ts b/aio/content/examples/toh-pt1/e2e/src/app.e2e-spec.ts index d15cc6a3dc..6b68069429 100644 --- a/aio/content/examples/toh-pt1/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/toh-pt1/e2e/src/app.e2e-spec.ts @@ -12,12 +12,12 @@ class Hero { // Get hero id and name from the given detail element. static async fromDetail(detail: ElementFinder): Promise { // Get hero id from the first
- let _id = await detail.all(by.css('div')).first().getText(); + let id = await detail.all(by.css('div')).first().getText(); // Get name from the h2 - let _name = await detail.element(by.css('h2')).getText(); + let name = await detail.element(by.css('h2')).getText(); return { - id: +_id.substr(_id.indexOf(' ') + 1), - name: _name.substr(0, _name.lastIndexOf(' ')) + id: +id.substr(id.indexOf(' ') + 1), + name: name.substr(0, name.lastIndexOf(' ')) }; } } diff --git a/aio/content/examples/toh-pt2/e2e/src/app.e2e-spec.ts b/aio/content/examples/toh-pt2/e2e/src/app.e2e-spec.ts index ab329d9ff9..563419cde0 100644 --- a/aio/content/examples/toh-pt2/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/toh-pt2/e2e/src/app.e2e-spec.ts @@ -24,12 +24,12 @@ class Hero { // Get hero id and name from the given detail element. static async fromDetail(detail: ElementFinder): Promise { // Get hero id from the first
- let _id = await detail.all(by.css('div')).first().getText(); + let id = await detail.all(by.css('div')).first().getText(); // Get name from the h2 - let _name = await detail.element(by.css('h2')).getText(); + let name = await detail.element(by.css('h2')).getText(); return { - id: +_id.substr(_id.indexOf(' ') + 1), - name: _name.substr(0, _name.lastIndexOf(' ')) + id: +id.substr(id.indexOf(' ') + 1), + name: name.substr(0, name.lastIndexOf(' ')) }; } } diff --git a/aio/content/examples/toh-pt3/e2e/src/app.e2e-spec.ts b/aio/content/examples/toh-pt3/e2e/src/app.e2e-spec.ts index e3bb115a3b..6cc55b0cd2 100644 --- a/aio/content/examples/toh-pt3/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/toh-pt3/e2e/src/app.e2e-spec.ts @@ -24,12 +24,12 @@ class Hero { // Get hero id and name from the given detail element. static async fromDetail(detail: ElementFinder): Promise { // Get hero id from the first
- let _id = await detail.all(by.css('div')).first().getText(); + let id = await detail.all(by.css('div')).first().getText(); // Get name from the h2 - let _name = await detail.element(by.css('h2')).getText(); + let name = await detail.element(by.css('h2')).getText(); return { - id: +_id.substr(_id.indexOf(' ') + 1), - name: _name.substr(0, _name.lastIndexOf(' ')) + id: +id.substr(id.indexOf(' ') + 1), + name: name.substr(0, name.lastIndexOf(' ')) }; } } diff --git a/aio/content/examples/toh-pt4/e2e/src/app.e2e-spec.ts b/aio/content/examples/toh-pt4/e2e/src/app.e2e-spec.ts index 3003360328..66e4f51fd4 100644 --- a/aio/content/examples/toh-pt4/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/toh-pt4/e2e/src/app.e2e-spec.ts @@ -24,12 +24,12 @@ class Hero { // Get hero id and name from the given detail element. static async fromDetail(detail: ElementFinder): Promise { // Get hero id from the first
- let _id = await detail.all(by.css('div')).first().getText(); + let id = await detail.all(by.css('div')).first().getText(); // Get name from the h2 - let _name = await detail.element(by.css('h2')).getText(); + let name = await detail.element(by.css('h2')).getText(); return { - id: +_id.substr(_id.indexOf(' ') + 1), - name: _name.substr(0, _name.lastIndexOf(' ')) + id: +id.substr(id.indexOf(' ') + 1), + name: name.substr(0, name.lastIndexOf(' ')) }; } } diff --git a/aio/content/examples/toh-pt5/e2e/src/app.e2e-spec.ts b/aio/content/examples/toh-pt5/e2e/src/app.e2e-spec.ts index d953578e78..ab6431ea7f 100644 --- a/aio/content/examples/toh-pt5/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/toh-pt5/e2e/src/app.e2e-spec.ts @@ -25,12 +25,12 @@ class Hero { // Get hero id and name from the given detail element. static async fromDetail(detail: ElementFinder): Promise { // Get hero id from the first
- let _id = await detail.all(by.css('div')).first().getText(); + let id = await detail.all(by.css('div')).first().getText(); // Get name from the h2 - let _name = await detail.element(by.css('h2')).getText(); + let name = await detail.element(by.css('h2')).getText(); return { - id: +_id.substr(_id.indexOf(' ') + 1), - name: _name.substr(0, _name.lastIndexOf(' ')) + id: +id.substr(id.indexOf(' ') + 1), + name: name.substr(0, name.lastIndexOf(' ')) }; } } 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 8cc6517b30..860516e300 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 @@ -32,12 +32,12 @@ class Hero { // Hero id and name from the given detail element. static async fromDetail(detail: ElementFinder): Promise { // Get hero id from the first
- let _id = await detail.all(by.css('div')).first().getText(); + let id = await detail.all(by.css('div')).first().getText(); // Get name from the h2 - let _name = await detail.element(by.css('h2')).getText(); + let name = await detail.element(by.css('h2')).getText(); return { - id: +_id.substr(_id.indexOf(' ') + 1), - name: _name.substr(0, _name.lastIndexOf(' ')) + id: +id.substr(id.indexOf(' ') + 1), + name: name.substr(0, name.lastIndexOf(' ')) }; } } diff --git a/aio/content/examples/upgrade-phonecat-1-typescript/app/core/phone/phone.service.spec.ts b/aio/content/examples/upgrade-phonecat-1-typescript/app/core/phone/phone.service.spec.ts index ed34d0a502..0339bf4a50 100644 --- a/aio/content/examples/upgrade-phonecat-1-typescript/app/core/phone/phone.service.spec.ts +++ b/aio/content/examples/upgrade-phonecat-1-typescript/app/core/phone/phone.service.spec.ts @@ -1,3 +1,4 @@ +// tslint:disable: variable-name describe('Phone', () => { let $httpBackend: angular.IHttpBackendService; let Phone: any; diff --git a/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-detail/phone-detail.component.spec.ts b/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-detail/phone-detail.component.spec.ts index 7063858784..38a3ecfcef 100644 --- a/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-detail/phone-detail.component.spec.ts +++ b/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-detail/phone-detail.component.spec.ts @@ -1,3 +1,4 @@ +// tslint:disable: variable-name // #docregion describe('phoneDetail', () => { diff --git a/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-list/phone-list.component.spec.ts b/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-list/phone-list.component.spec.ts index 212992cfa3..975191f4de 100644 --- a/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-list/phone-list.component.spec.ts +++ b/aio/content/examples/upgrade-phonecat-1-typescript/app/phone-list/phone-list.component.spec.ts @@ -1,3 +1,4 @@ +// tslint:disable: variable-name describe('phoneList', () => { // Load the module that contains the `phoneList` component before each test diff --git a/aio/content/examples/upgrade-phonecat-2-hybrid/app/core/phone/phone.service.spec.ts b/aio/content/examples/upgrade-phonecat-2-hybrid/app/core/phone/phone.service.spec.ts index 8cf877fe42..96f719f834 100644 --- a/aio/content/examples/upgrade-phonecat-2-hybrid/app/core/phone/phone.service.spec.ts +++ b/aio/content/examples/upgrade-phonecat-2-hybrid/app/core/phone/phone.service.spec.ts @@ -1,3 +1,4 @@ +// tslint:disable: variable-name // #docregion import { inject, TestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; diff --git a/aio/content/examples/upgrade-phonecat-3-final/app/core/phone/phone.service.spec.ts b/aio/content/examples/upgrade-phonecat-3-final/app/core/phone/phone.service.spec.ts index 4fdcca005c..f6c79d5591 100644 --- a/aio/content/examples/upgrade-phonecat-3-final/app/core/phone/phone.service.spec.ts +++ b/aio/content/examples/upgrade-phonecat-3-final/app/core/phone/phone.service.spec.ts @@ -1,3 +1,4 @@ +// tslint:disable: variable-name import { inject, TestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { Phone, PhoneData } from './phone.service';