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
This commit is contained in:
George Kalpakas 2020-07-30 13:03:17 +03:00 committed by Alex Rickabaugh
parent 1db4f508e6
commit ba11f7b90b
22 changed files with 77 additions and 76 deletions

View File

@ -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;

View File

@ -86,13 +86,11 @@ function getPageElts() {
async function heroFromDetail(detail: ElementFinder): Promise<Hero> {
// Get hero id from the first <div>
// 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(' ')),
};
}

View File

@ -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', () => {

View File

@ -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 = '"<no name set>"';
let emptyNameIndex = 1;
let defaultName = '"<no name set>"';
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);
});
}
// ...

View File

@ -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: '<h3>"{{name}}"</h3>'
})
export class NameChildComponent {
private _name = '';
@Input()
get name(): string { return this._name; }
set name(name: string) {
this._name = (name && name.trim()) || '<no name set>';
}
get name(): string { return this._name; }
private _name = '';
}
// #enddocregion

View File

@ -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', () => {

View File

@ -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);
});
});

View File

@ -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();

View File

@ -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
}

View File

@ -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;
};
}

View File

@ -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);

View File

@ -12,12 +12,12 @@ class Hero {
// Get hero id and name from the given detail element.
static async fromDetail(detail: ElementFinder): Promise<Hero> {
// Get hero id from the first <div>
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(' '))
};
}
}

View File

@ -24,12 +24,12 @@ class Hero {
// Get hero id and name from the given detail element.
static async fromDetail(detail: ElementFinder): Promise<Hero> {
// Get hero id from the first <div>
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(' '))
};
}
}

View File

@ -24,12 +24,12 @@ class Hero {
// Get hero id and name from the given detail element.
static async fromDetail(detail: ElementFinder): Promise<Hero> {
// Get hero id from the first <div>
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(' '))
};
}
}

View File

@ -24,12 +24,12 @@ class Hero {
// Get hero id and name from the given detail element.
static async fromDetail(detail: ElementFinder): Promise<Hero> {
// Get hero id from the first <div>
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(' '))
};
}
}

View File

@ -25,12 +25,12 @@ class Hero {
// Get hero id and name from the given detail element.
static async fromDetail(detail: ElementFinder): Promise<Hero> {
// Get hero id from the first <div>
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(' '))
};
}
}

View File

@ -32,12 +32,12 @@ class Hero {
// Hero id and name from the given detail element.
static async fromDetail(detail: ElementFinder): Promise<Hero> {
// Get hero id from the first <div>
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(' '))
};
}
}

View File

@ -1,3 +1,4 @@
// tslint:disable: variable-name
describe('Phone', () => {
let $httpBackend: angular.IHttpBackendService;
let Phone: any;

View File

@ -1,3 +1,4 @@
// tslint:disable: variable-name
// #docregion
describe('phoneDetail', () => {

View File

@ -1,3 +1,4 @@
// tslint:disable: variable-name
describe('phoneList', () => {
// Load the module that contains the `phoneList` component before each test

View File

@ -1,3 +1,4 @@
// tslint:disable: variable-name
// #docregion
import { inject, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';

View File

@ -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';