Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗 Enable a lint rule to auto-sort destructure keys #34523

Merged
merged 2 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
'prettier',
'react',
'react-hooks',
'sort-destructure-keys',
'sort-imports-es6-autofix',
'sort-requires',
],
Expand Down Expand Up @@ -251,6 +252,7 @@ module.exports = {
},
},
],
'sort-destructure-keys/sort-destructure-keys': 2,
'sort-imports-es6-autofix/sort-imports-es6': [
2,
{
Expand Down
2 changes: 1 addition & 1 deletion ads/google/a4a/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export function googlePageParameters(a4a, startTime) {
]).then((promiseResults) => {
const clientId = promiseResults[0];
const referrer = promiseResults[1];
const {pageViewId, canonicalUrl} = Services.documentInfoForDoc(ampDoc);
const {canonicalUrl, pageViewId} = Services.documentInfoForDoc(ampDoc);
// Read by GPT for GA/GPT integration.
win.gaGlobal = win.gaGlobal || {cid: clientId, hid: pageViewId};
const {screen} = win;
Expand Down
14 changes: 7 additions & 7 deletions ads/google/ima/ima-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function renderElements(elementOrDoc) {

// Buttons toggle SVGs by including two each, one is displayed at a time.
// See CSS selectors for buttons under .root[data-*].
const {'playButton': playButton, 'muteButton': muteButton} = elements;
const {'muteButton': muteButton, 'playButton': playButton} = elements;

playButton.appendChild(icons.play(svg));
playButton.appendChild(icons.pause(svg));
Expand Down Expand Up @@ -388,10 +388,10 @@ export function imaVideo(global, data) {
imaLoadAllowed = true;

const {
'fullscreenButton': fullscreenButton,
'muteButton': muteButton,
'playButton': playButton,
'progress': progress,
'muteButton': muteButton,
'fullscreenButton': fullscreenButton,
} = elements;

let mobileBrowser = false;
Expand Down Expand Up @@ -592,7 +592,7 @@ function onImaLoadFail() {
* @visibleForTesting
*/
export function onOverlayButtonInteract(global) {
const {'video': video, 'overlayButton': overlayButton} = elements;
const {'overlayButton': overlayButton, 'video': video} = elements;
if (playbackStarted) {
// Resart the video
playVideo();
Expand Down Expand Up @@ -862,7 +862,7 @@ export function onContentPauseRequested(global) {
* @visibleForTesting
*/
export function onContentResumeRequested() {
const {'video': video, 'overlayButton': overlayButton} = elements;
const {'overlayButton': overlayButton, 'video': video} = elements;
adsActive = false;
addHoverEventToElement(
/** @type {!Element} */ (video),
Expand Down Expand Up @@ -949,9 +949,9 @@ function playerDataTick() {
*/
export function updateTime(currentTime, duration) {
const {
'time': time,
'progressLine': progressLine,
'progressMarker': progressMarker,
'time': time,
} = elements;
time.textContent = formatTime(currentTime) + ' / ' + formatTime(duration);
const progressPercent = Math.floor((currentTime / duration) * 100);
Expand Down Expand Up @@ -1031,7 +1031,7 @@ function onProgressClickEnd() {
* @param {!Event} event
*/
function onProgressMove(event) {
const {'video': video, 'progress': progress} = elements;
const {'progress': progress, 'video': video} = elements;
const progressWrapperPosition = getPagePosition(progress);
const progressListStart = progressWrapperPosition.x;
const progressListWidth = progress./*OK*/ offsetWidth;
Expand Down
2 changes: 1 addition & 1 deletion ads/inabox/frame-overlay-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const expandFrameImpl = function (win, iframe, onFinish) {
);
},
mutate(state) {
const {width, height} = state.viewportSize;
const {height, width} = state.viewportSize;
const expandedRect = layoutRectLtwh(0, 0, width, height);

centerFrameUnderVsyncMutate(
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/adform.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const hosts = {
export function adform(global, data) {
validateData(data, [['src', 'bn', 'mid']]);
global.Adform = {ampData: data};
const {src, bn, mid} = data;
const {bn, mid, src} = data;
let url;

// Custom ad url using "data-src" attribute
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/imonomy.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function reportStats(data, code) {
if (typeof window.context.location.href !== 'undefined') {
pageLocation = encodeURIComponent(window.context.location.href);
}
const {subId, pid} = data,
const {pid, subId} = data,
trackId = 'AMP',
notFirst = true,
cid = '',
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/ketshwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {validateData, writeScript} from '../../3p/3p';
export function ketshwa(global, data) {
validateData(data, ['widgetid', 'externalid'], []);

const {widgetid, externalid} = data;
const {externalid, widgetid} = data;
const skey = `widget_${widgetid}`;

const dv = global.document.createElement('div');
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/onnetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const hosts = {
export function onnetwork(global, data) {
validateData(data, [['src', 'sid', 'mid']]);
global.onnetwork = {ampData: data};
const {src, sid, mid} = data;
const {mid, sid, src} = data;
let url;

// Custom movie url using "data-src" attribute
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/vmfive.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function vmfive(global, data) {
const mandatory_fields = ['appKey', 'placementId', 'adType'];
const optional_fields = [];

const {appKey, placementId, adType} = data;
const {adType, appKey, placementId} = data;

global._vmfive_amp = {appKey, placementId, adType};

Expand Down
2 changes: 1 addition & 1 deletion build-system/babel-config/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const {getReplacePlugin, getReplaceGlobalsPlugin} = require('./helpers');
const {getReplaceGlobalsPlugin, getReplacePlugin} = require('./helpers');

/**
* Gets the config for babel transforms run during `amp [unit|integration|e2e]`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* and getMode().localDev to true.
* @param {Object} babelTypes
*/
const {resolve, dirname, join, relative} = require('path').posix;
const {dirname, join, relative, resolve} = require('path').posix;

let shouldResolveDevelopmentMode = true;

Expand All @@ -35,7 +35,7 @@ module.exports = function ({types: t}) {
},
visitor: {
ImportDeclaration({node}, state) {
const {specifiers, source} = node;
const {source, specifiers} = node;
if (!source.value.endsWith('/mode')) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function (babel) {
let shouldEmitTypedefs;
return {
pre() {
const {writeToFile = false, emitTypedefs = false} = this.opts;
const {emitTypedefs = false, writeToFile = false} = this.opts;
shouldWriteToFile = writeToFile;
shouldEmitTypedefs = emitTypedefs;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const {resolve, dirname, relative, join} = require('path').posix;
const {dirname, join, relative, resolve} = require('path').posix;

/**
* Returns a new Map<string, {detected: boolean, removeable: Array<string>}
Expand Down Expand Up @@ -62,7 +62,7 @@ module.exports = function () {
},
ImportDeclaration({node}, state) {
// Only remove the CallExpressions if this module imported the correct method ('dev') from '/log'.
const {specifiers, source} = node;
const {source, specifiers} = node;
if (!source.value.endsWith('/log')) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = function ({types: t}) {
* @return {ReturnType<t['arrowFunctionExpression']>}
*/
function createArrowFunctionExpression(node) {
const {params, body, async} = t.cloneNode(node);
const {async, body, params} = t.cloneNode(node);
return t.arrowFunctionExpression(params, body.body[0].argument, async);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

const {
staticTemplateTags,
staticTemplateFactoryFns,
staticTemplateTags,
} = require('../static-template-metadata');
const {minify} = require('html-minifier');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function (babel, options = {}) {

TemplateElement(path) {
const {node} = path;
const {raw, cooked} = node.value;
const {cooked, raw} = node.value;
if (!raw.includes('$internalRuntimeVersion$')) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

const {dirname, join, relative, resolve} = require('path');
const {readFileSync} = require('fs');
const {resolve, dirname, join, relative} = require('path');

// Transforms JSON imports into a `JSON.parse` call:
//
Expand All @@ -28,7 +28,7 @@ const {resolve, dirname, join, relative} = require('path');
// ```
// const key = JSON.parse('{"imported": "json"}');
// ```
module.exports = function ({types: t, template}, options) {
module.exports = function ({template, types: t}, options) {
const {freeze = true} = options;

return {
Expand All @@ -38,7 +38,7 @@ module.exports = function ({types: t, template}, options) {

visitor: {
ImportDeclaration(path) {
const {specifiers, assertions, source} = path.node;
const {assertions, source, specifiers} = path.node;
if (!assertions || assertions.length === 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const hash = require('./create-hash');
const {addNamed} = require('@babel/helper-module-imports');
const {create} = require('jss');
const {default: preset} = require('jss-preset-default');
const {relative, join} = require('path');
const {join, relative} = require('path');
const {transformCssSync} = require('../../tasks/css/jsify-css-sync');

module.exports = function ({template, types: t}) {
Expand Down
4 changes: 2 additions & 2 deletions build-system/common/ctrlcHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

const colors = require('./colors');
const {execScriptAsync, exec} = require('./exec');
const {exec, execScriptAsync} = require('./exec');
const {logLocalDev} = require('./logging');

const {green, cyan} = colors;
const {cyan, green} = colors;

const killCmd = process.platform == 'win32' ? 'taskkill /f /pid' : 'kill -KILL';
const killSuffix = process.platform == 'win32' ? '>NUL' : '';
Expand Down
4 changes: 2 additions & 2 deletions build-system/common/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*/

const {
isCiBuild,
isPullRequestBuild,
ciPullRequestBranch,
ciPullRequestSha,
isCiBuild,
isPullRequestBuild,
} = require('./ci');
const {getStdout} = require('./process');

Expand Down
2 changes: 1 addition & 1 deletion build-system/common/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
'use strict';

const {bold, yellow, gray} = require('./colors');
const {bold, gray, yellow} = require('./colors');
const {isCiBuild} = require('./ci');

/**
Expand Down
2 changes: 1 addition & 1 deletion build-system/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const experimentsConfig = require('../global-configs/experiments-config.json');
const fs = require('fs-extra');
const globby = require('globby');
const {clean} = require('../tasks/clean');
const {cyan, green, red, yellow} = require('./colors');
const {default: ignore} = require('ignore');
const {doBuild} = require('../tasks/build');
const {doDist} = require('../tasks/dist');
const {gitDiffNameOnlyMain} = require('./git');
const {green, cyan, red, yellow} = require('./colors');
const {log, logLocalDev} = require('./logging');

/**
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/check-for-unknown-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs-extra');
const {cyan, red, yellow} = require('../common/colors');
const {log} = require('../common/logging');
const {red, cyan, yellow} = require('../common/colors');

/**
* Searches for the identifier "module$", which Closure uses to uniquely
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const path = require('path');
const {checkForUnknownDeps} = require('./check-for-unknown-deps');
const {CLOSURE_SRC_GLOBS} = require('./sources');
const {cpus} = require('os');
const {green, cyan} = require('../common/colors');
const {cyan, green} = require('../common/colors');
const {log, logLocalDev} = require('../common/logging');
const {postClosureBabel} = require('./post-closure-babel');
const {preClosureBabel} = require('./pre-closure-babel');
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/post-closure-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const fs = require('fs-extra');
const path = require('path');
const Remapping = require('@ampproject/remapping');
const terser = require('terser');
const {debug, CompilationLifecycles} = require('./debug-compilation-lifecycle');
const {CompilationLifecycles, debug} = require('./debug-compilation-lifecycle');
const {jsBundles} = require('./bundles.config.js');

/** @type {Remapping.default} */
Expand Down
4 changes: 2 additions & 2 deletions build-system/compile/pre-closure-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const globby = require('globby');
const path = require('path');
const tempy = require('tempy');
const {BABEL_SRC_GLOBS} = require('./sources');
const {debug, CompilationLifecycles} = require('./debug-compilation-lifecycle');
const {CompilationLifecycles, debug} = require('./debug-compilation-lifecycle');
const {cyan, red} = require('../common/colors');
const {log} = require('../common/logging');
const {red, cyan} = require('../common/colors');
const {TransformCache, batchedRead, md5} = require('../common/transform-cache');

/**
Expand Down
4 changes: 2 additions & 2 deletions build-system/eslint-rules/closure-type-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function checkClosureComments(context, closureComment) {
return;
}

const {parsed, node} = closureComment;
const {node, parsed} = closureComment;
traverse(parsed).forEach((astNode) => {
if (!astNode) {
return;
Expand Down Expand Up @@ -158,7 +158,7 @@ function checkNonNullableNodes(context, node, astNode) {
return;
}

const {type, name} = astNode.expression;
const {name, type} = astNode.expression;
if (type === 'FunctionType') {
reportNonNullablePrimitive(context, node, 'function');
} else if (type === 'UndefinedLiteral') {
Expand Down
4 changes: 2 additions & 2 deletions build-system/eslint-rules/html-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

const {
staticTemplateFactories,
staticTemplateTags,
staticTemplateFactoryFns,
staticTemplateTags,
} = require('../babel-plugins/static-template-metadata');

/**
Expand Down Expand Up @@ -125,7 +125,7 @@ module.exports = function (context) {
const {start} = template;

for (let i = 0; i < invalids.length; i++) {
const {tag, offset} = invalids[i];
const {offset, tag} = invalids[i];
context.report({
node: template,
loc: sourceCode.getLocFromIndex(start + offset),
Expand Down
2 changes: 1 addition & 1 deletion build-system/eslint-rules/no-array-destructuring.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function (context) {
}

if (callee.type === 'MemberExpression') {
const {object, property, computed} = callee;
const {computed, object, property} = callee;
if (computed) {
return false;
}
Expand Down
Loading