diff --git a/.eslintignore b/.eslintignore index 10f501cc..07fcb643 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,3 @@ node_modules coverage/ -/packages/generator-open-wc/generators/*/templates/**/* \ No newline at end of file +/packages/generator-open-wc/generators/*/templates/**/* diff --git a/.eslintrc.js b/.eslintrc.js index a018cc01..182ffc2d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,6 @@ module.exports = { extends: [ './packages/eslint-config/index.js', + require.resolve('eslint-config-prettier'), ], }; diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..07fcb643 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +node_modules +coverage/ +/packages/generator-open-wc/generators/*/templates/**/* diff --git a/husky.config.js b/husky.config.js index 718bbcd8..4c2ec3ae 100644 --- a/husky.config.js +++ b/husky.config.js @@ -1,6 +1,6 @@ module.exports = { hooks: { - 'pre-commit': 'npm run lint', + 'pre-commit': 'lint-staged', 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', }, }; diff --git a/package.json b/package.json index 3c6fa174..bea239bd 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "bootstrap": "lerna bootstrap --hoist --no-ci", "lint": "run-p lint:*", "lint:eslint": "eslint --ext .js,.html .", + "lint:prettier": "prettier packages/**/*.js --write", "publish": "lerna publish --message 'chore: release new versions'", "site:build": "npm run vuepress:build", "site:start": "npm run vuepress:start", @@ -15,13 +16,23 @@ "vuepress:build": "vuepress build docs", "vuepress:start": "vuepress dev docs" }, + "lint-staged": { + "*.js": [ + "eslint --fix", + "prettier --write", + "git add" + ] + }, "devDependencies": { "@commitlint/cli": "7.2.1", "@commitlint/config-conventional": "7.1.2", "@commitlint/config-lerna-scopes": "7.2.1", + "eslint-config-prettier": "^3.3.0", "husky": "1.1.2", "lerna": "3.4.3", + "lint-staged": "^8.1.0", "npm-run-all": "4.1.3", + "prettier": "^1.15.0", "vuepress": "1.0.0-alpha.18" } } diff --git a/packages/chai-dom-equals/chai-dom-equals.js b/packages/chai-dom-equals/chai-dom-equals.js index dc628466..639e209d 100644 --- a/packages/chai-dom-equals/chai-dom-equals.js +++ b/packages/chai-dom-equals/chai-dom-equals.js @@ -4,11 +4,11 @@ import { getSemanticDomDiff } from '@open-wc/semantic-dom-diff'; * el.outerHTML is not polyfilled so we need to recreate the tag + attributes and * combine it with el.innerHTML. */ -export const getOuterHtml = (el) => { +export const getOuterHtml = el => { if (window.ShadyCSS && window.ShadyCSS.nativeShadow === false) { const tagName = el.tagName.toLowerCase(); let attributes = ' '; - Array.prototype.slice.call(el.attributes).forEach((item) => { + Array.prototype.slice.call(el.attributes).forEach(item => { attributes += `${item.name}="${item.value}" `; }); // removes last ' ' or if there are no attributes makes it to equal '' @@ -22,7 +22,7 @@ export const getOuterHtml = (el) => { * For comparision we do not need the style scoping classes on polyfilled browsers * Rather naive approach for now - probably need to improve once we have failing cases. */ -export const getCleanedShadowDom = (el) => { +export const getCleanedShadowDom = el => { if (window.ShadyCSS && window.ShadyCSS.nativeShadow === false) { const tagName = el.tagName.toLowerCase(); const regexTagName = new RegExp(tagName, 'g'); @@ -56,6 +56,7 @@ export const chaiDomEquals = (chai, utils) => { }); // can not be an arrow function as it gets rebound + // prettier-ignore const domEquals = _super => function handleDom(value, ...args) { if (!utils.flag(this, 'semantically') && utils.flag(this, 'dom')) { const expected = getOuterHtml(this._obj); diff --git a/packages/chai-dom-equals/karma.conf.js b/packages/chai-dom-equals/karma.conf.js index 4c5ef9c2..2902a8de 100644 --- a/packages/chai-dom-equals/karma.conf.js +++ b/packages/chai-dom-equals/karma.conf.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies const createBaseConfig = require('@open-wc/testing-karma/create-karma-config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/chai-dom-equals/karma.es5.bs.config.js b/packages/chai-dom-equals/karma.es5.bs.config.js index 04305582..b0e0b847 100644 --- a/packages/chai-dom-equals/karma.es5.bs.config.js +++ b/packages/chai-dom-equals/karma.es5.bs.config.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies const createBaseConfig = require('@open-wc/testing-karma-bs/create-karma-es5-bs.config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/chai-dom-equals/wallaby.js b/packages/chai-dom-equals/wallaby.js index 694b0ed9..2efec33f 100644 --- a/packages/chai-dom-equals/wallaby.js +++ b/packages/chai-dom-equals/wallaby.js @@ -5,9 +5,7 @@ const wallabyPostprocessor = wallabyWebpack({ resolve: { modules: [path.resolve(__dirname, 'bower_components'), 'node_modules'], }, - entryPatterns: [ - 'test/index.js', - ], + entryPatterns: ['test/index.js'], }); module.exports = () => ({ @@ -19,15 +17,14 @@ module.exports = () => ({ { pattern: 'test/index.js', load: false }, { pattern: 'test/*.test.js', ignore: true }, ], - tests: [ - { pattern: 'test/*.test.js', load: false }, - ], + tests: [{ pattern: 'test/*.test.js', load: false }], testFramework: 'mocha', debug: true, env: { kind: 'chrome', params: { - runner: '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', + runner: + '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', }, }, postprocessor: wallabyPostprocessor, diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index 470739f6..0233c68d 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -1,7 +1,5 @@ module.exports = { - extends: [ - 'eslint-config-airbnb-base', - ].map(require.resolve), + extends: ['eslint-config-airbnb-base'].map(require.resolve), parser: 'babel-eslint', env: { browser: true, @@ -11,12 +9,12 @@ module.exports = { 'import/extensions': 'off', 'no-underscore-dangle': 'off', 'import/prefer-default-export': 'off', - 'import/no-extraneous-dependencies': ['error', { - devDependencies: [ - '**/test/*.js', - '**/stories/*.js', - ], - }], + 'import/no-extraneous-dependencies': [ + 'error', + { + devDependencies: ['**/test/*.js', '**/stories/*.js'], + }, + ], }, settings: { 'import/resolver': { diff --git a/packages/semantic-dom-diff/karma.conf.js b/packages/semantic-dom-diff/karma.conf.js index a9d8d2f9..287d9666 100644 --- a/packages/semantic-dom-diff/karma.conf.js +++ b/packages/semantic-dom-diff/karma.conf.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies const createBaseConfig = require('@open-wc/testing-karma/create-karma-config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/semantic-dom-diff/karma.es5.bs.config.js b/packages/semantic-dom-diff/karma.es5.bs.config.js index e22b6893..ad553e4c 100644 --- a/packages/semantic-dom-diff/karma.es5.bs.config.js +++ b/packages/semantic-dom-diff/karma.es5.bs.config.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies const createBaseConfig = require('@open-wc/testing-karma-bs/create-karma-es5-bs.config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/semantic-dom-diff/wallaby.js b/packages/semantic-dom-diff/wallaby.js index 694b0ed9..2efec33f 100644 --- a/packages/semantic-dom-diff/wallaby.js +++ b/packages/semantic-dom-diff/wallaby.js @@ -5,9 +5,7 @@ const wallabyPostprocessor = wallabyWebpack({ resolve: { modules: [path.resolve(__dirname, 'bower_components'), 'node_modules'], }, - entryPatterns: [ - 'test/index.js', - ], + entryPatterns: ['test/index.js'], }); module.exports = () => ({ @@ -19,15 +17,14 @@ module.exports = () => ({ { pattern: 'test/index.js', load: false }, { pattern: 'test/*.test.js', ignore: true }, ], - tests: [ - { pattern: 'test/*.test.js', load: false }, - ], + tests: [{ pattern: 'test/*.test.js', load: false }], testFramework: 'mocha', debug: true, env: { kind: 'chrome', params: { - runner: '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', + runner: + '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', }, }, postprocessor: wallabyPostprocessor, diff --git a/packages/testing-helpers/fixture.js b/packages/testing-helpers/fixture.js index 3d9a21aa..10e58bd1 100644 --- a/packages/testing-helpers/fixture.js +++ b/packages/testing-helpers/fixture.js @@ -31,7 +31,7 @@ export function fixtureSync(template, props = {}) { parent.innerHTML = template; const element = parent.children[0]; const properties = typeof props === 'function' ? props(element) : props; - Object.keys(properties).forEach((prop) => { + Object.keys(properties).forEach(prop => { element[prop] = properties[prop]; }); const wrapper = new FixtureWrapper(); diff --git a/packages/testing-helpers/helpers.js b/packages/testing-helpers/helpers.js index e8a94331..b8920b90 100644 --- a/packages/testing-helpers/helpers.js +++ b/packages/testing-helpers/helpers.js @@ -37,7 +37,7 @@ export function isIE() { * @returns {Promise} */ export async function aTimeout(ms) { - return new Promise((resolve) => { + return new Promise(resolve => { setTimeout(resolve, ms); }); } @@ -76,7 +76,7 @@ export async function triggerFocusFor(element) { * @returns {Promise} */ export async function oneEvent(element, eventName) { - return new Promise((resolve) => { + return new Promise(resolve => { function listener(ev) { resolve(ev); element.removeEventListener(eventName, listener); @@ -97,7 +97,7 @@ export async function nextFrame() { * @returns {Promise} */ export async function flush() { - return new Promise((resolve) => { + return new Promise(resolve => { if (window.flush) { window.flush(() => { resolve(); diff --git a/packages/testing-helpers/index.js b/packages/testing-helpers/index.js index 33dcaca4..a15b2848 100644 --- a/packages/testing-helpers/index.js +++ b/packages/testing-helpers/index.js @@ -1,6 +1,12 @@ export { html, unsafeStatic } from './lit-html.js'; export { - triggerBlurFor, triggerFocusFor, oneEvent, isIE, defineCE, aTimeout, nextFrame, + triggerBlurFor, + triggerFocusFor, + oneEvent, + isIE, + defineCE, + aTimeout, + nextFrame, } from './helpers.js'; export { litFixture, litFixtureSync } from './litFixture.js'; export { fixture, fixtureSync } from './fixture.js'; diff --git a/packages/testing-helpers/karma.conf.js b/packages/testing-helpers/karma.conf.js index b04473b1..52fa541e 100644 --- a/packages/testing-helpers/karma.conf.js +++ b/packages/testing-helpers/karma.conf.js @@ -1,6 +1,6 @@ const createBaseConfig = require('../testing-karma/create-karma-config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/testing-helpers/karma.es5.bs.config.js b/packages/testing-helpers/karma.es5.bs.config.js index e22b6893..ad553e4c 100644 --- a/packages/testing-helpers/karma.es5.bs.config.js +++ b/packages/testing-helpers/karma.es5.bs.config.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies const createBaseConfig = require('@open-wc/testing-karma-bs/create-karma-es5-bs.config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/testing-helpers/lit-html.js b/packages/testing-helpers/lit-html.js index 87db73d1..4c1cf01b 100644 --- a/packages/testing-helpers/lit-html.js +++ b/packages/testing-helpers/lit-html.js @@ -28,7 +28,7 @@ export function html(strings, ...values) { } const isDynamicProp = p => p && p.d && typeof p.d === 'string' && Object.keys(p).length === 1; - const addToCurrentString = (add) => { + const addToCurrentString = add => { newStr[newStr.length - 1] = newStr[newStr.length - 1] + add; }; diff --git a/packages/testing-helpers/wallaby.js b/packages/testing-helpers/wallaby.js index a99025b2..b0f510a5 100644 --- a/packages/testing-helpers/wallaby.js +++ b/packages/testing-helpers/wallaby.js @@ -8,21 +8,15 @@ const wallabyPostprocessor = wallabyWebpack({ }); module.exports = () => ({ - files: [ - '*.js', - '!wallaby.js', - '!*.config.js', - '!*.conf.js', - ], - tests: [ - 'test/*.test.js', - ], + files: ['*.js', '!wallaby.js', '!*.config.js', '!*.conf.js'], + tests: ['test/*.test.js'], testFramework: 'mocha', debug: true, env: { kind: 'chrome', params: { - runner: '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', + runner: + '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', }, }, postprocessor: wallabyPostprocessor, diff --git a/packages/testing-karma-bs/create-karma-es5-bs.config.js b/packages/testing-karma-bs/create-karma-es5-bs.config.js index 1daec2b9..5b620ace 100644 --- a/packages/testing-karma-bs/create-karma-es5-bs.config.js +++ b/packages/testing-karma-bs/create-karma-es5-bs.config.js @@ -24,7 +24,7 @@ if (!process.env.BROWSER_STACK_USERNAME || !process.env.BROWSER_STACK_ACCESS_KEY * * See demo/karma.es5.config.js for an example implementation. */ -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); return { diff --git a/packages/testing-karma/create-karma-config.js b/packages/testing-karma/create-karma-config.js index 1a21b1ea..8df719f5 100644 --- a/packages/testing-karma/create-karma-config.js +++ b/packages/testing-karma/create-karma-config.js @@ -6,17 +6,12 @@ const path = require('path'); * See demo/karma.conf.js for an example implementation. */ module.exports = config => ({ - browsers: [ - 'ChromeHeadlessNoSandbox', - ], + browsers: ['ChromeHeadlessNoSandbox'], customLaunchers: { ChromeHeadlessNoSandbox: { base: 'ChromeHeadless', - flags: [ - '--no-sandbox', - '--disable-setuid-sandbox', - ], + flags: ['--no-sandbox', '--disable-setuid-sandbox'], }, }, diff --git a/packages/testing-karma/create-karma-es5.config.js b/packages/testing-karma/create-karma-es5.config.js index 03c6f14c..7cadab95 100644 --- a/packages/testing-karma/create-karma-es5.config.js +++ b/packages/testing-karma/create-karma-es5.config.js @@ -10,15 +10,21 @@ const createBaseConfig = require('./create-karma-config'); * * See demo/karma.es5.config.js for an example implementation. */ -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); return { ...baseConfig, files: [ { pattern: require.resolve('@babel/polyfill/browser'), watched: false }, - { pattern: require.resolve('@webcomponents/webcomponentsjs/custom-elements-es5-adapter'), watched: false }, - { pattern: require.resolve('@webcomponents/webcomponentsjs/webcomponents-bundle'), watched: false }, + { + pattern: require.resolve('@webcomponents/webcomponentsjs/custom-elements-es5-adapter'), + watched: false, + }, + { + pattern: require.resolve('@webcomponents/webcomponentsjs/webcomponents-bundle'), + watched: false, + }, ], webpack: { @@ -30,9 +36,7 @@ module.exports = (config) => { test: /\.js$/, loader: 'babel-loader', options: { - presets: [ - ['@babel/preset-env', { targets: 'IE 11' }], - ], + presets: [['@babel/preset-env', { targets: 'IE 11' }]], cacheDirectory: true, }, }, diff --git a/packages/testing/index-no-side-effects.js b/packages/testing/index-no-side-effects.js index d26b366d..c03d38ed 100644 --- a/packages/testing/index-no-side-effects.js +++ b/packages/testing/index-no-side-effects.js @@ -13,9 +13,4 @@ export { fixtureSync, } from '@open-wc/testing-helpers'; -export { - chai, - expect, - should, - assert, -} from '@bundled-es-modules/chai'; +export { chai, expect, should, assert } from '@bundled-es-modules/chai'; diff --git a/packages/testing/index.js b/packages/testing/index.js index d60d5c56..49dfe2b0 100644 --- a/packages/testing/index.js +++ b/packages/testing/index.js @@ -16,9 +16,4 @@ export { fixtureSync, } from '@open-wc/testing-helpers'; -export { - chai, - expect, - should, - assert, -} from '@bundled-es-modules/chai'; +export { chai, expect, should, assert } from '@bundled-es-modules/chai'; diff --git a/packages/testing/karma.conf.js b/packages/testing/karma.conf.js index 98dd9825..160b9c6c 100644 --- a/packages/testing/karma.conf.js +++ b/packages/testing/karma.conf.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies const createBaseConfig = require('@open-wc/testing-karma/create-karma-config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/testing/karma.es5.bs.config.js b/packages/testing/karma.es5.bs.config.js index 1ba1c48b..6a9e9159 100644 --- a/packages/testing/karma.es5.bs.config.js +++ b/packages/testing/karma.es5.bs.config.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies const createBaseConfig = require('@open-wc/testing-karma-bs/create-karma-es5-bs.config'); -module.exports = (config) => { +module.exports = config => { const baseConfig = createBaseConfig(config); config.set({ diff --git a/packages/testing/register-fixture-cleanup.js b/packages/testing/register-fixture-cleanup.js index a714d0b8..e7a01060 100644 --- a/packages/testing/register-fixture-cleanup.js +++ b/packages/testing/register-fixture-cleanup.js @@ -3,7 +3,7 @@ import { cachedWrappers } from '@open-wc/testing-helpers/fixture.js'; if (afterEach) { afterEach(() => { if (cachedWrappers) { - cachedWrappers.forEach((wrapper) => { + cachedWrappers.forEach(wrapper => { document.body.removeChild(wrapper); }); } diff --git a/packages/testing/wallaby.js b/packages/testing/wallaby.js index 694b0ed9..2efec33f 100644 --- a/packages/testing/wallaby.js +++ b/packages/testing/wallaby.js @@ -5,9 +5,7 @@ const wallabyPostprocessor = wallabyWebpack({ resolve: { modules: [path.resolve(__dirname, 'bower_components'), 'node_modules'], }, - entryPatterns: [ - 'test/index.js', - ], + entryPatterns: ['test/index.js'], }); module.exports = () => ({ @@ -19,15 +17,14 @@ module.exports = () => ({ { pattern: 'test/index.js', load: false }, { pattern: 'test/*.test.js', ignore: true }, ], - tests: [ - { pattern: 'test/*.test.js', load: false }, - ], + tests: [{ pattern: 'test/*.test.js', load: false }], testFramework: 'mocha', debug: true, env: { kind: 'chrome', params: { - runner: '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', + runner: + '--no-sandbox --disable-setuid-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-background-networking --safebrowsing-disable-auto-update --disable-sync --metrics-recording-only --disable-default-apps --no-first-run', }, }, postprocessor: wallabyPostprocessor, diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 00000000..0ac81de7 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1 @@ +module.exports = require('./packages/prettier-config');