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