From 30d797a06e92bc0ea397f84f4388330573cf16fe Mon Sep 17 00:00:00 2001 From: Stefan Cameron Date: Sat, 29 Aug 2020 17:19:53 -0500 Subject: [PATCH] Move to trailing commas with Prettier Only to the extent that ES5 permits them. This is the new default for Prettier, and actually makes a lot of sense when editing code as well as reviewing code changes. Also update what code gets linted. --- .prettierrc.js | 4 ++-- CHANGELOG.md | 1 + babel.config.js | 4 ++-- demo/js/allowoutsideclick.js | 4 ++-- demo/js/default.js | 2 +- demo/js/hidden-treasures.js | 2 +- demo/js/iframe.js | 2 +- demo/js/initial-element-no-escape.js | 2 +- demo/js/initially-focused-container.js | 2 +- demo/js/input-activation.js | 2 +- demo/js/nested.js | 4 ++-- demo/js/radio.js | 2 +- demo/js/set-return-focus.js | 2 +- demo/js/sibling.js | 4 ++-- demo/js/tricky-initial-focus.js | 2 +- index.js | 18 ++++++++-------- package.json | 2 +- webpack.config.js | 30 +++++++++++++------------- 18 files changed, 45 insertions(+), 44 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index 827549b4..950a7d6c 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -15,6 +15,6 @@ module.exports = { semi: true, singleQuote: true, tabWidth: 2, - trailingComma: 'none', - useTabs: false + trailingComma: 'es5', + useTabs: false, }; diff --git a/CHANGELOG.md b/CHANGELOG.md index 639c5d92..10f586fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add boolean value support for `allowOutsideClick` option - New `preventScroll` feature to *prevent* scrolling to the element getting focus if not in the viewport. +- Changed code formatting to use dangling commas where ES5 supports them. ## 5.1.0 diff --git a/babel.config.js b/babel.config.js index 7c8e2081..824c80ed 100644 --- a/babel.config.js +++ b/babel.config.js @@ -4,6 +4,6 @@ module.exports = { // ECMAScript 2015+ code by default, which is the original preset prior // to upgrading to Babel 7 // @see https://babeljs.io/docs/en/babel-preset-env#targets - '@babel/preset-env' - ] + '@babel/preset-env', + ], }; diff --git a/demo/js/allowoutsideclick.js b/demo/js/allowoutsideclick.js index dcdbab6c..08924b3a 100644 --- a/demo/js/allowoutsideclick.js +++ b/demo/js/allowoutsideclick.js @@ -14,7 +14,7 @@ function initialize() { }, onDeactivate: function () { container.className = 'trap'; - } + }, }); } @@ -55,7 +55,7 @@ document if (e.target === trigger) { return true; } - } + }, }[event.target.value]; focusTrap = initialize(); diff --git a/demo/js/default.js b/demo/js/default.js index 27e33ce8..e837d642 100644 --- a/demo/js/default.js +++ b/demo/js/default.js @@ -8,7 +8,7 @@ var focusTrap = createFocusTrap('#default', { }, onDeactivate: function () { container.className = 'trap'; - } + }, }); document diff --git a/demo/js/hidden-treasures.js b/demo/js/hidden-treasures.js index 5b3fda06..5cf9253e 100644 --- a/demo/js/hidden-treasures.js +++ b/demo/js/hidden-treasures.js @@ -9,7 +9,7 @@ var focusTrap = createFocusTrap(container, { }, onDeactivate: function () { container.className = 'trap'; - } + }, }); document.getElementById('activate-ht').addEventListener('click', function () { diff --git a/demo/js/iframe.js b/demo/js/iframe.js index 172581d4..07155142 100644 --- a/demo/js/iframe.js +++ b/demo/js/iframe.js @@ -8,7 +8,7 @@ var focusTrap = createFocusTrap('#iframe', { }, onDeactivate: function () { container.className = 'trap'; - } + }, }); document diff --git a/demo/js/initial-element-no-escape.js b/demo/js/initial-element-no-escape.js index a9d339e7..e2d4ee7c 100644 --- a/demo/js/initial-element-no-escape.js +++ b/demo/js/initial-element-no-escape.js @@ -10,7 +10,7 @@ var focusTrap = createFocusTrap(container, { container.className = 'trap'; }, initialFocus: '#focused-input', - escapeDeactivates: false + escapeDeactivates: false, }); document.getElementById('activate-iene').addEventListener('click', function () { diff --git a/demo/js/initially-focused-container.js b/demo/js/initially-focused-container.js index e098fe34..ca768d7e 100644 --- a/demo/js/initially-focused-container.js +++ b/demo/js/initially-focused-container.js @@ -12,7 +12,7 @@ var focusTrap = createFocusTrap('#ifc', { initialFocus: function () { return document.getElementById('ifc'); }, - clickOutsideDeactivates: true + clickOutsideDeactivates: true, }); document.getElementById('activate-ifc').addEventListener('click', function () { diff --git a/demo/js/input-activation.js b/demo/js/input-activation.js index 21ccacc4..f2f0c651 100644 --- a/demo/js/input-activation.js +++ b/demo/js/input-activation.js @@ -8,7 +8,7 @@ var focusTrap = createFocusTrap(container, { }, onDeactivate: function () { container.className = 'trap'; - } + }, }); document diff --git a/demo/js/nested.js b/demo/js/nested.js index 8312788b..f9e943ea 100644 --- a/demo/js/nested.js +++ b/demo/js/nested.js @@ -6,14 +6,14 @@ var nested = document.getElementById('nested-nested'); var primaryFocusTrap = createFocusTrap('#nested', { onDeactivate: function () { container.style.display = 'none'; - } + }, }); var nestedFocusTrap = createFocusTrap('#nested-nested', { onDeactivate: function () { nested.style.display = 'none'; primaryFocusTrap.unpause(); - } + }, }); document diff --git a/demo/js/radio.js b/demo/js/radio.js index 8813f9ac..fad6b79e 100644 --- a/demo/js/radio.js +++ b/demo/js/radio.js @@ -8,7 +8,7 @@ var focusTrap = createFocusTrap('#radio', { }, onDeactivate: function () { container.className = 'trap'; - } + }, }); document diff --git a/demo/js/set-return-focus.js b/demo/js/set-return-focus.js index f3322442..a70f3684 100644 --- a/demo/js/set-return-focus.js +++ b/demo/js/set-return-focus.js @@ -9,7 +9,7 @@ var focusTrap = createFocusTrap('#setreturnfocus', { onDeactivate: function () { container.className = 'trap'; }, - setReturnFocus: '#overwritten-element' + setReturnFocus: '#overwritten-element', }); document diff --git a/demo/js/sibling.js b/demo/js/sibling.js index 903cd42e..56035669 100644 --- a/demo/js/sibling.js +++ b/demo/js/sibling.js @@ -6,14 +6,14 @@ var second = document.getElementById('sibling-second'); var firstFocusTrap = createFocusTrap('#sibling-first', { onDeactivate: function () { container.className = 'trap'; - } + }, }); var secondFocusTrap = createFocusTrap('#sibling-second', { onDeactivate: function () { second.style.display = 'none'; second.className = 'trap'; - } + }, }); document diff --git a/demo/js/tricky-initial-focus.js b/demo/js/tricky-initial-focus.js index 4ec73f10..2417c949 100644 --- a/demo/js/tricky-initial-focus.js +++ b/demo/js/tricky-initial-focus.js @@ -10,7 +10,7 @@ var focusTrap = createFocusTrap(container, { }, onDeactivate: function () { container.className = 'trap'; - } + }, }); document.getElementById('activate-tif').addEventListener('click', function () { diff --git a/index.js b/index.js index 4764ee30..288bc168 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,7 @@ var activeFocusTraps = (function () { if (trapQueue.length > 0) { trapQueue[trapQueue.length - 1].unpause(); } - } + }, }; })(); @@ -44,7 +44,7 @@ function focusTrap(element, userOptions) { var config = { returnFocusOnDeactivate: true, escapeDeactivates: true, - ...userOptions + ...userOptions, }; var state = { @@ -53,14 +53,14 @@ function focusTrap(element, userOptions) { nodeFocusedBeforeActivation: null, mostRecentlyFocusedNode: null, active: false, - paused: false + paused: false, }; var trap = { activate: activate, deactivate: deactivate, pause: pause, - unpause: unpause + unpause: unpause, }; return trap; @@ -146,19 +146,19 @@ function focusTrap(element, userOptions) { doc.addEventListener('focusin', checkFocusIn, true); doc.addEventListener('mousedown', checkPointerDown, { capture: true, - passive: false + passive: false, }); doc.addEventListener('touchstart', checkPointerDown, { capture: true, - passive: false + passive: false, }); doc.addEventListener('click', checkClick, { capture: true, - passive: false + passive: false, }); doc.addEventListener('keydown', checkKey, { capture: true, - passive: false + passive: false, }); return trap; @@ -227,7 +227,7 @@ function focusTrap(element, userOptions) { if (container.contains(e.target)) return; if (config.clickOutsideDeactivates) { deactivate({ - returnFocus: !tabbable.isFocusable(e.target) + returnFocus: !tabbable.isFocusable(e.target), }); return; } diff --git a/package.json b/package.json index 7e6baa5f..81efce5f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "format": "prettier --write \"{*,src/**/*,test/**/*,demo/js/**/*,.github/workflows/*}.+(js|yml)\"", "format-check": "prettier --check \"{*,src/**/*,test/**/*,demo/js/**/*,.github/workflows/*}.+(js|yml)\"", - "lint": "eslint .", + "lint": "eslint \"*.js\" \"demo/**/*.js\"", "clean": "del-cli dist && make-dir dist", "build": "yarn clean && webpack", "start": "budo demo/js/index.js:demo-bundle.js --dir demo --live -- -t babelify", diff --git a/webpack.config.js b/webpack.config.js index b4e607f4..6986d341 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -25,7 +25,7 @@ const config = { // variable names and static values to their shortest representation // possible while maintaining critical names // @see https://webpack.js.org/guides/tree-shaking/ - minimize: true + minimize: true, }, module: { rules: [ @@ -34,28 +34,28 @@ const config = { exclude: /node_modules/, use: { loader: 'babel-loader', - options: babelConfig - } - } - ] + options: babelConfig, + }, + }, + ], }, plugins: [ new BannerPlugin({ banner: getBanner(), - raw: true - }) + raw: true, + }), ], watchOptions: { // @see https://webpack.js.org/configuration/watch/ - ignored: ['node_modules/**', 'dist/**', '**/*.spec.js', '**/*.test.js'] - } + ignored: ['node_modules/**', 'dist/**', '**/*.spec.js', '**/*.test.js'], + }, }; const outputConfig = { path: path.resolve('./dist'), libraryTarget: 'umd', library: 'focusTrap', - filename: null // specify in specialized build config + filename: null, // specify in specialized build config }; module.exports = [ @@ -65,8 +65,8 @@ module.exports = [ name: 'dev', output: { ...outputConfig, - filename: `${pkg.name}.js` - } + filename: `${pkg.name}.js`, + }, }, // Prod build { @@ -76,7 +76,7 @@ module.exports = [ devtool: false, // no source map output: { ...outputConfig, - filename: `${pkg.name}.min.js` - } - } + filename: `${pkg.name}.min.js`, + }, + }, ];