Commit ebc2c0d2 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Merge .eslintrc.js in core/script/layered_api/ subdirectories into one

elements/toast/.eslintrc.js and kv-storage/.eslintrc.js were identical,
and elements/virtual-scroller/.eslintrc.js had some differences.  The
following describes differences between them and decision for them.

* virtual-scroller had '2' for no-magic-numbers exceptions.
 We keep the '2' exception.

* virtual-scroller enabled max-len.
 We enable max-len.
 max-len is helpful because clang-format doesn't support *.mjs extension
 for now.

* virtual-scroller had no no-lonely-if and no no-else-return.
 We drop them.
 Following these rules is sometimes harmful for code consistency.

Change-Id: Icf3118e4d504248a55a284a763f7392c59793769
Bug: 976576
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1727447
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarDomenic Denicola <domenic@chromium.org>
Reviewed-by: default avatarFergal Daly <fergal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683107}
parent 9daf9f18
......@@ -73,7 +73,6 @@ module.exports = {
'no-caller': 'error',
'no-case-declarations': 'error',
'no-div-regex': 'off',
'no-else-return': 'error',
'no-empty-function': 'off',
'no-empty-pattern': 'error',
'no-eq-null': 'error',
......@@ -94,7 +93,7 @@ module.exports = {
'no-labels': ['error', {allowLoop: true}],
'no-lone-blocks': 'error',
'no-loop-func': 'error',
'no-magic-numbers': ['error', {ignore: [0, 1]}],
'no-magic-numbers': ['error', {ignore: [0, 1, 2]}],
'no-multi-spaces': ['error', {ignoreEOLComments: true}],
'no-multi-str': 'error',
'no-new': 'error',
......@@ -204,7 +203,9 @@ module.exports = {
'linebreak-style': ['error', 'unix'],
'lines-around-comment': 'off',
'max-depth': 'off',
'max-len': 'off',
'max-len': ['error', {
tabWidth: 2,
ignorePattern: "(^import |// eslint-disable-line |https?://)"}],
'max-lines': 'off',
'max-nested-callbacks': 'off',
'max-params': 'off',
......@@ -218,7 +219,6 @@ module.exports = {
'no-bitwise': 'off',
'no-continue': 'off',
'no-inline-comments': 'off',
'no-lonely-if': 'error',
'no-mixed-operators': [
'error',
{
......
......@@ -17,12 +17,12 @@
* this argument is omitted.
*/
export function installBool(proto, attrName, propName = attrName) {
let getter = function() {
function getter() {
return this.hasAttribute(attrName);
};
let setter = function(value) {
}
function setter(value) {
this.toggleAttribute(attrName, Boolean(value));
};
}
Object.defineProperty(
getter, 'name',
{configurable: true, enumerable: false, value: 'get ' + propName});
......@@ -44,13 +44,13 @@ export function installBool(proto, attrName, propName = attrName) {
* this argument is omitted.
*/
export function installString(proto, attrName, propName = attrName) {
let getter = function() {
let value = this.getAttribute(attrName);
function getter() {
const value = this.getAttribute(attrName);
return value === null ? '' : value;
};
let setter = function(value) {
}
function setter(value) {
this.setAttribute(attrName, value);
};
}
Object.defineProperty(
getter, 'name',
{configurable: true, enumerable: false, value: 'get ' + propName});
......
......@@ -37,36 +37,36 @@ function installGetter(proto, propName, getter) {
export function installPropertiesAndFunctions(proto, internals) {
reflection.installBool(proto, 'disabled');
reflection.installString(proto, 'name');
installGetter(proto, 'type', function() {
installGetter(proto, 'type', function () {
if (!(this instanceof proto.constructor)) {
throw TypeError(
throw new TypeError(
'The context object is not an instance of ' + proto.contructor.name);
}
return this.localName;
});
installGetter(proto, 'form', function() {
installGetter(proto, 'form', function () {
return this[internals].form;
});
installGetter(proto, 'willValidate', function() {
installGetter(proto, 'willValidate', function () {
return this[internals].willValidate;
});
installGetter(proto, 'validity', function() {
installGetter(proto, 'validity', function () {
return this[internals].validity;
});
installGetter(proto, 'validationMessage', function() {
installGetter(proto, 'validationMessage', function () {
return this[internals].validationMessage;
});
installGetter(proto, 'labels', function() {
installGetter(proto, 'labels', function () {
return this[internals].labels;
});
proto.checkValidity = function() {
proto.checkValidity = function () {
return this[internals].checkValidity();
};
proto.reportValidity = function() {
proto.reportValidity = function () {
return this[internals].reportValidity();
};
proto.setCustomValidity = function(error) {
proto.setCustomValidity = function (error) {
if (error === undefined) {
throw new TypeError('Too few arguments');
}
......
......@@ -4,7 +4,7 @@
import * as face from './face_utils.mjs';
import * as reflection from '../internal/reflection.mjs';
import { SwitchTrack } from './track.mjs';
import {SwitchTrack} from './track.mjs';
import * as style from './style.mjs';
const generateStyleSheet = style.styleSheetFactory();
......@@ -14,10 +14,10 @@ const STATE_ATTR = 'on';
// Private property symbols
// TODO(tkent): Use private fields.
const _internals = Symbol();
const _track = Symbol();
const _rippleElement = Symbol();
const _containerElement = Symbol();
const _internals = Symbol('an ElementInternals field');
const _track = Symbol('a track element field');
const _rippleElement = Symbol('a ripple element field');
const _containerElement = Symbol('A container element field');
export class StdSwitchElement extends HTMLElement {
// TODO(tkent): The following should be |static fooBar = value;|
......@@ -43,7 +43,7 @@ export class StdSwitchElement extends HTMLElement {
}
attributeChangedCallback(attrName, oldValue, newValue) {
if (attrName == STATE_ATTR) {
if (attrName === STATE_ATTR) {
this[_track].value = newValue !== null;
// TODO(tkent): We should not add aria-checked attribute.
// https://github.com/WICG/aom/issues/127
......@@ -67,8 +67,8 @@ export class StdSwitchElement extends HTMLElement {
// TODO(tkent): Make this private.
_initializeDOM() {
let factory = this.ownerDocument;
let root = this.attachShadow({mode: 'closed'});
const factory = this.ownerDocument;
const root = this.attachShadow({mode: 'closed'});
this[_containerElement] = factory.createElement('span');
this[_containerElement].id = 'container';
// Shadow elements should be invisible for a11y technologies.
......@@ -79,19 +79,21 @@ export class StdSwitchElement extends HTMLElement {
this[_containerElement].appendChild(this[_track].element);
this[_track].value = this.on;
let thumbElement = this[_containerElement].appendChild(factory.createElement('span'));
const thumbElement =
this[_containerElement].appendChild(factory.createElement('span'));
thumbElement.id = 'thumb';
thumbElement.part.add('thumb');
this[_rippleElement] = thumbElement.appendChild(factory.createElement('span'));
this[_rippleElement] =
thumbElement.appendChild(factory.createElement('span'));
this[_rippleElement].id = 'ripple';
root.adoptedStyleSheets = [generateStyleSheet()];
}
// TODO(tkent): Make this private.
_onClick(event) {
for (let element of this[_containerElement].querySelectorAll('*')) {
_onClick() {
for (const element of this[_containerElement].querySelectorAll('*')) {
style.markTransition(element);
}
this.on = !this.on;
......@@ -101,7 +103,7 @@ export class StdSwitchElement extends HTMLElement {
// TODO(tkent): Make this private.
_onKeyPress(event) {
if (event.code == 'Space') {
if (event.code === 'Space') {
// Do not scroll the page.
event.preventDefault();
this._onClick(event);
......@@ -120,7 +122,7 @@ Object.defineProperty(StdSwitchElement.prototype, Symbol.toStringTag, {
configurable: true,
enumerable: false,
value: 'StdSwitchElement',
writable: false
writable: false,
});
customElements.define('std-switch', StdSwitchElement);
......
......@@ -164,20 +164,21 @@ function setupTransitionCounter(element) {
++element.runningTransitions;
}
});
let handleEndOrCancel = e => {
function handleEndOrCancel(e) {
// Need to check runningTransitions>0 due to superfluous transitioncancel
// events; crbug.com/979556.
if (e.target === element && element.runningTransitions > 0) {
--element.runningTransitions;
}
};
}
element.addEventListener('transitionend', handleEndOrCancel);
element.addEventListener('transitioncancel', handleEndOrCancel);
}
/**
* Add '$part-transitioning' part to the element, and remove it on 'transitionend'
* event or remove it immediately if the element has no transitions.
* Add '$part-transitioning' part to the element, and remove it on
* 'transitionend' event or remove it immediately if the element has no
* transitions.
*
* TODO(tkent): We should apply custom state.
*
......@@ -211,14 +212,14 @@ export function markTransition(element) {
// If the element has a transition, it must start on the rendering just
// after this rAF callback. So we check runningTransitions in the next
// frame.
const removeIfNoTransitions = () => {
function removeIfNoTransitions() {
// No transitions started, or all transitions were completed.
if (element.runningTransitions === 0) {
element.part.remove(partName);
} else {
window.requestAnimationFrame(removeIfNoTransitions);
}
};
}
window.requestAnimationFrame(removeIfNoTransitions);
});
}
......@@ -4,13 +4,12 @@
// Private property symbols
// TODO(tkent): Use private fields.
const _value = Symbol();
const _trackElement = Symbol();
const _fillElement = Symbol();
const _slotElement = Symbol();
const _value = Symbol('A boolean track value field');
const _trackElement = Symbol('A track element field');
const _fillElement = Symbol('A trackFill element field');
const _slotElement = Symbol('A slot element field');
export class SwitchTrack {
/**
* @param {!Document} factory A factory for elements created for this track.
*/
......@@ -30,13 +29,13 @@ export class SwitchTrack {
* @param {Boolean} newValue
*/
set value(newValue) {
let oldValue = this[_value];
const oldValue = this[_value];
this[_value] = Boolean(newValue);
let bar = this[_fillElement];
const bar = this[_fillElement];
if (bar) {
bar.style.inlineSize = this[_value] ? '100%' : '0%';
if (oldValue != this[_value]) {
if (oldValue !== this[_value]) {
this._addSlot();
}
}
......
......@@ -52,8 +52,8 @@ function styleSheetFactory() {
border-color: red;
}
`);
// TODO(jacksteinberg): use offset-block-end: / offset-inline-end: over bottom: / right:
// when implemented https://bugs.chromium.org/p/chromium/issues/detail?id=538475
// TODO(jacksteinberg): use offset-block-end: / offset-inline-end: over
// bottom: / right: when implemented http://crbug.com/538475.
}
return stylesheet;
};
......@@ -108,7 +108,8 @@ export class StdToastElement extends HTMLElement {
if (!this.hasAttribute('role')) {
this.setAttribute('role', 'status');
}
// TODO(jacksteinberg): use https://github.com/whatwg/html/pull/4658 when implemented
// TODO(jacksteinberg): use https://github.com/whatwg/html/pull/4658
// when implemented
}
get action() {
......@@ -172,7 +173,8 @@ export class StdToastElement extends HTMLElement {
show({duration = DEFAULT_DURATION} = {}) {
if (duration <= 0) {
throw new RangeError(`Invalid Argument: duration must be greater than 0 [${duration} given]`);
throw new RangeError(`Invalid Argument: duration must be greater ` +
`than 0 [${duration} given]`);
}
this.setAttribute('open', '');
......
......@@ -73,12 +73,13 @@ export class StorageArea {
async clear() {
if (!this.#databasePromise) {
// Don't try to delete, and clear the promise, while we're opening the database; wait for that
// first.
// Don't try to delete, and clear the promise, while we're opening the
// database; wait for that first.
try {
await this.#databasePromise;
} catch {
// If the database failed to initialize, then that's fine, we'll still try to delete it.
// If the database failed to initialize, then that's fine, we'll still
// try to delete it.
}
this.#databasePromise = undefined;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment