diff --git a/.eslintrc.js b/.eslintrc.js index 55a0692..09708a8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,7 +11,11 @@ module.exports = { }, }, plugins: ["ember"], - extends: ["eslint:recommended", "plugin:ember/recommended"], + extends: [ + "eslint:recommended", + "plugin:ember/recommended", + "plugin:prettier/recommended", + ], env: { browser: true, }, diff --git a/addon/components/ember-islands.js b/addon/components/ember-islands.js index dce490b..1ca92d2 100644 --- a/addon/components/ember-islands.js +++ b/addon/components/ember-islands.js @@ -1,12 +1,12 @@ -import Ember from 'ember'; -import Reconciler from 'ember-islands/utils/reconciler'; -import queryIslandComponents from 'ember-islands/utils/query-island-components'; -import getRenderComponent from 'ember-islands/utils/get-render-component'; +import Ember from "ember"; +import Reconciler from "ember-islands/utils/reconciler"; +import queryIslandComponents from "ember-islands/utils/query-island-components"; +import getRenderComponent from "ember-islands/utils/get-render-component"; let eiInstance; export default Ember.Component.extend({ - tagName: '', + tagName: "", init() { this._super(...arguments); @@ -24,7 +24,7 @@ export default Ember.Component.extend({ destroy(c) { c.destroy(); - } + }, }); eiInstance = this; @@ -43,8 +43,8 @@ export default Ember.Component.extend({ }, willDestroyElement() { - this.reconciler.forEachRenderedComponent(c => c.destroy()); - } + this.reconciler.forEachRenderedComponent((c) => c.destroy()); + }, }); export function getInstance() { diff --git a/addon/index.js b/addon/index.js index 1f3ad55..d0f1d84 100644 --- a/addon/index.js +++ b/addon/index.js @@ -1,4 +1,4 @@ -import { getInstance } from './components/ember-islands'; +import { getInstance } from "./components/ember-islands"; export function reconcile() { getInstance().reconcile(); diff --git a/addon/utils/get-render-component.js b/addon/utils/get-render-component.js index e29a8f4..237ec54 100644 --- a/addon/utils/get-render-component.js +++ b/addon/utils/get-render-component.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import Ember from "ember"; const { getOwner, Component, Logger } = Ember; export default function getRenderComponent(emberObject) { @@ -10,14 +10,19 @@ export default function getRenderComponent(emberObject) { // This can only be true in production mode where assert is a no-op. if (!component) { - ({ component, layout } = provideMissingComponentInProductionMode(owner, name)); + ({ component, layout } = provideMissingComponentInProductionMode( + owner, + name + )); } if (layout) { attrs.layout = layout; } - while (element.firstChild) { element.removeChild(element.firstChild); } + while (element.firstChild) { + element.removeChild(element.firstChild); + } let componentInstance = component.create(attrs); componentInstance.appendTo(element); @@ -46,5 +51,5 @@ function missingComponentMessage(name) { function provideMissingComponentInProductionMode(owner, name) { Logger.error(missingComponentMessage(name)); - return lookupComponent(owner, 'ember-islands/missing-component'); + return lookupComponent(owner, "ember-islands/missing-component"); } diff --git a/addon/utils/query-island-components.js b/addon/utils/query-island-components.js index eb22076..b0b37e1 100644 --- a/addon/utils/query-island-components.js +++ b/addon/utils/query-island-components.js @@ -11,12 +11,12 @@ */ export default function queryIslandComponents() { let components = []; - let islandNodeList = document.querySelectorAll('[data-component]'); + let islandNodeList = document.querySelectorAll("[data-component]"); // Avoid NodeList.prototype.forEach for IE 11 compatibility. for (let i = 0; i < islandNodeList.length; i++) { let element = islandNodeList[i]; - let name = element.getAttribute('data-component'); + let name = element.getAttribute("data-component"); let attrs = componentAttributes(element); components.push({ attrs, name, element, instance: undefined }); } @@ -26,7 +26,7 @@ export default function queryIslandComponents() { function componentAttributes(element) { let attrs; - let attrsJSON = element.getAttribute('data-attrs'); + let attrsJSON = element.getAttribute("data-attrs"); if (attrsJSON) { attrs = JSON.parse(attrsJSON); diff --git a/addon/utils/reconciler.js b/addon/utils/reconciler.js index 70c7e6b..53c8238 100644 --- a/addon/utils/reconciler.js +++ b/addon/utils/reconciler.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import Ember from "ember"; const { guidFor } = Ember; export default class Reconciler { @@ -13,7 +13,7 @@ export default class Reconciler { reconcileAgainst(componentsToRender) { let nextRenderedComponents = {}; - componentsToRender.forEach(ic => { + componentsToRender.forEach((ic) => { let elementGuid = guidFor(ic.element); let renderedIC = this.renderedComponents[elementGuid]; diff --git a/app/components/ember-islands.js b/app/components/ember-islands.js index 9a300b2..f59865a 100644 --- a/app/components/ember-islands.js +++ b/app/components/ember-islands.js @@ -1 +1 @@ -export { default } from 'ember-islands/components/ember-islands'; +export { default } from "ember-islands/components/ember-islands"; diff --git a/app/components/ember-islands/missing-component.js b/app/components/ember-islands/missing-component.js index a3e1d83..62051cd 100644 --- a/app/components/ember-islands/missing-component.js +++ b/app/components/ember-islands/missing-component.js @@ -1,3 +1,3 @@ -import Ember from 'ember'; +import Ember from "ember"; export default Ember.Component.extend(); diff --git a/package.json b/package.json index f9ce47d..3b9a9a2 100644 --- a/package.json +++ b/package.json @@ -51,10 +51,13 @@ "ember-template-lint": "^2.8.0", "ember-try": "^1.4.0", "eslint": "^7.1.0", + "eslint-config-prettier": "^6.11.0", "eslint-plugin-ember": "^8.6.0", "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^3.1.4", "loader.js": "^4.7.0", "npm-run-all": "^4.1.5", + "prettier": "^2.0.5", "qunit-dom": "^1.2.0" }, "engines": { diff --git a/tests/acceptance/inner-content-test.js b/tests/acceptance/inner-content-test.js index f455886..211a2ba 100644 --- a/tests/acceptance/inner-content-test.js +++ b/tests/acceptance/inner-content-test.js @@ -1,12 +1,12 @@ -import Ember from 'ember'; -import { module, test } from 'qunit'; -import startApp from '../helpers/start-app'; +import Ember from "ember"; +import { module, test } from "qunit"; +import startApp from "../helpers/start-app"; var application; -module('Acceptance: Using Inner Content', { - beforeEach: function() { - document.getElementById('ember-testing').innerHTML = ` +module("Acceptance: Using Inner Content", { + beforeEach: function () { + document.getElementById("ember-testing").innerHTML = `
server-rendered content top
server-rendered content bottom
@@ -17,49 +17,77 @@ module('Acceptance: Rendering Components', { application = startApp(); }, - afterEach: function() { - Ember.run(application, 'destroy'); - document.getElementById('ember-testing').innerHTML = ''; - } + afterEach: function () { + Ember.run(application, "destroy"); + document.getElementById("ember-testing").innerHTML = ""; + }, }); -test('rendering a component with an attribute', function(assert) { +test("rendering a component with an attribute", function (assert) { assert.expect(2); - visit('/'); + visit("/"); - andThen(function() { - assert.equal(find('p:contains(top level component)').length, 1, "The top level component was rendered"); - assert.equal(find('#component-title:contains(Component Title)').length, 1, "Passed in attributes can be used"); + andThen(function () { + assert.equal( + find("p:contains(top level component)").length, + 1, + "The top level component was rendered" + ); + assert.equal( + find("#component-title:contains(Component Title)").length, + 1, + "Passed in attributes can be used" + ); }); }); -test('using component events', function(assert) { +test("using component events", function (assert) { assert.expect(2); - visit('/'); + visit("/"); - andThen(function() { - assert.equal(find("#expanded-content").length, 0, "Expanded content is hidden at first"); + andThen(function () { + assert.equal( + find("#expanded-content").length, + 0, + "Expanded content is hidden at first" + ); }); - click('#toggle-expanded'); + click("#toggle-expanded"); - andThen(function() { - assert.equal(find("#expanded-content").length, 1, "The expanded content is showing"); + andThen(function () { + assert.equal( + find("#expanded-content").length, + 1, + "The expanded content is showing" + ); }); }); -test('using nested components', function(assert) { +test("using nested components", function (assert) { assert.expect(3); - visit('/'); + visit("/"); - andThen(function() { - assert.equal(find('p:contains(A nested component)').length, 1, "The nested component was rendered"); - assert.equal(find("#expanded-content").length, 0, "Expanded content is hidden at first"); + andThen(function () { + assert.equal( + find("p:contains(A nested component)").length, + 1, + "The nested component was rendered" + ); + assert.equal( + find("#expanded-content").length, + 0, + "Expanded content is hidden at first" + ); }); - click('#nested-component-toggle-expanded'); + click("#nested-component-toggle-expanded"); - andThen(function() { - assert.equal(find("#expanded-content").length, 1, "The expanded content is showing"); + andThen(function () { + assert.equal( + find("#expanded-content").length, + 1, + "The expanded content is showing" + ); }); }); diff --git a/tests/dummy/app/components/dummy-application.js b/tests/dummy/app/components/dummy-application.js index ed67458..140e3e8 100644 --- a/tests/dummy/app/components/dummy-application.js +++ b/tests/dummy/app/components/dummy-application.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import Ember from "ember"; export default Ember.Component.extend({ init() { @@ -8,7 +8,7 @@ export default Ember.Component.extend({ actions: { toggleIslandComponents() { - this.toggleProperty('isShowingIslandComponents'); - } - } + this.toggleProperty("isShowingIslandComponents"); + }, + }, }); diff --git a/tests/dummy/app/components/inner-content-component.js b/tests/dummy/app/components/inner-content-component.js index ff14d98..9903c30 100644 --- a/tests/dummy/app/components/inner-content-component.js +++ b/tests/dummy/app/components/inner-content-component.js @@ -1,5 +1,5 @@ -import Ember from 'ember'; +import Ember from "ember"; export default Ember.Component.extend({ - classNameBindings: [':inner-content-component'] + classNameBindings: [":inner-content-component"], }); diff --git a/tests/dummy/app/components/js-only-component.js b/tests/dummy/app/components/js-only-component.js index 0314b3e..fbb482f 100644 --- a/tests/dummy/app/components/js-only-component.js +++ b/tests/dummy/app/components/js-only-component.js @@ -1,11 +1,11 @@ -import Ember from 'ember'; +import Ember from "ember"; const { Component } = Ember; export default Component.extend({ - classNames: ['js-only-component'], + classNames: ["js-only-component"], onDidInsertElement() { - this.element.innerHTML = 'js-only-component'; - } + this.element.innerHTML = "js-only-component"; + }, }); diff --git a/tests/dummy/app/components/nested-component.js b/tests/dummy/app/components/nested-component.js index 327c065..b3e7dc7 100644 --- a/tests/dummy/app/components/nested-component.js +++ b/tests/dummy/app/components/nested-component.js @@ -1,11 +1,11 @@ -import Ember from 'ember'; +import Ember from "ember"; export default Ember.Component.extend({ isExpanded: false, actions: { - nestedAction: function() { - this.sendAction('nestedAction'); - } - } + nestedAction: function () { + this.sendAction("nestedAction"); + }, + }, }); diff --git a/tests/dummy/app/components/stateful-component.js b/tests/dummy/app/components/stateful-component.js index 55a3395..c0c141b 100644 --- a/tests/dummy/app/components/stateful-component.js +++ b/tests/dummy/app/components/stateful-component.js @@ -1,9 +1,9 @@ -import Ember from 'ember'; +import Ember from "ember"; const { Component, computed } = Ember; export default Component.extend({ - tagName: 'button', + tagName: "button", init() { this._super(...arguments); @@ -12,15 +12,15 @@ export default Component.extend({ }, click() { - this.incrementProperty('count'); + this.incrementProperty("count"); }, - trimmedInnerContent: computed('innerContent', function() { - return this.get('innerContent').trim(); + trimmedInnerContent: computed("innerContent", function () { + return this.innerContent.trim(); }), destroy() { this.destroyCallCount++; this._super(...arguments); - } + }, }); diff --git a/tests/dummy/app/components/top-level-component.js b/tests/dummy/app/components/top-level-component.js index d3bdffe..4e1bb53 100644 --- a/tests/dummy/app/components/top-level-component.js +++ b/tests/dummy/app/components/top-level-component.js @@ -1,12 +1,12 @@ -import Ember from 'ember'; +import Ember from "ember"; export default Ember.Component.extend({ isExpanded: false, - classNameBindings: [':top-level-component'], + classNameBindings: [":top-level-component"], actions: { - toggleIsExpanded: function() { - this.toggleProperty('isExpanded', true); - } - } + toggleIsExpanded: function () { + this.toggleProperty("isExpanded", true); + }, + }, }); diff --git a/tests/integration/components/ember-islands-test.js b/tests/integration/components/ember-islands-test.js index eb47704..d337ce5 100644 --- a/tests/integration/components/ember-islands-test.js +++ b/tests/integration/components/ember-islands-test.js @@ -1,15 +1,15 @@ -import $ from 'jquery'; -import Ember from 'ember'; +import $ from "jquery"; +import Ember from "ember"; const { Component } = Ember; -import { moduleForComponent, test, skip } from 'ember-qunit'; -import hbs from 'htmlbars-inline-precompile'; +import { moduleForComponent, test, skip } from "ember-qunit"; +import hbs from "htmlbars-inline-precompile"; -moduleForComponent('ember-islands', 'Integration | Component | ember islands', { - integration: true +moduleForComponent("ember-islands", "Integration | Component | ember islands", { + integration: true, }); -test('it renders an island component', function(assert) { - document.getElementById('ember-testing').innerHTML = ` +test("it renders an island component", function (assert) { + document.getElementById("ember-testing").innerHTML = ` `; @@ -17,11 +17,11 @@ test('it renders an island component', function(assert) { {{ember-islands}} `); - assert.equal($('.top-level-component').length, 1); + assert.equal($(".top-level-component").length, 1); }); -test("rendering a component that only has an hbs template file", function(assert) { - document.getElementById('ember-testing').innerHTML = ` +test("rendering a component that only has an hbs template file", function (assert) { + document.getElementById("ember-testing").innerHTML = ` `; @@ -29,11 +29,11 @@ test("rendering a component that only has an hbs template file", function(assert {{ember-islands}} `); - assert.equal($('.hbs-only-component').length, 1); + assert.equal($(".hbs-only-component").length, 1); }); -test("rendering a component that only has a JavaScript file", function(assert) { - document.getElementById('ember-testing').innerHTML = ` +test("rendering a component that only has a JavaScript file", function (assert) { + document.getElementById("ember-testing").innerHTML = ` `; @@ -41,31 +41,31 @@ test("rendering a component that only has a JavaScript file", function(assert) { {{ember-islands}} `); - assert.equal($('.js-only-component').length, 1); + assert.equal($(".js-only-component").length, 1); }); -test('it tears down an island component', function(assert) { +test("it tears down an island component", function (assert) { let teardownCalls = []; const IslandComponent = Component.extend({ - classNames: ['island-component'], + classNames: ["island-component"], willDestroyElement() { - teardownCalls.push('willDestroyElement'); + teardownCalls.push("willDestroyElement"); }, willDestroy() { - teardownCalls.push('willDestroy'); - } + teardownCalls.push("willDestroy"); + }, }); - this.register('component:island-component', IslandComponent); + this.register("component:island-component", IslandComponent); - document.getElementById('ember-testing').innerHTML = ` + document.getElementById("ember-testing").innerHTML = ` `; - this.set('isShowing', true); + this.set("isShowing", true); this.render(hbs` {{#if isShowing}} @@ -73,24 +73,32 @@ test('it tears down an island component', function(assert) { {{/if}} `); - assert.equal($('.island-component').length, 1, "Has component in DOM"); + assert.equal($(".island-component").length, 1, "Has component in DOM"); - this.set('isShowing', false); + this.set("isShowing", false); - assert.equal($('.island-compoment').length, 0, "Component removed from DOM"); + assert.equal($(".island-compoment").length, 0, "Component removed from DOM"); - assert.deepEqual(teardownCalls, ['willDestroyElement', 'willDestroy'], "All component teardown hooks called"); + assert.deepEqual( + teardownCalls, + ["willDestroyElement", "willDestroy"], + "All component teardown hooks called" + ); }); // Related issue: https://github.com/emberjs/ember.js/issues/15013 -skip("Provides usefull error message when a component can't be found", function(assert) { - document.getElementById('ember-testing').innerHTML = ` +skip("Provides usefull error message when a component can't be found", function (assert) { + document.getElementById("ember-testing").innerHTML = ` `; - assert.throws(() => { - this.render(hbs` + assert.throws( + () => { + this.render(hbs` {{ember-islands}} `); - }, /could not find a component/, "Threw the correct error message"); + }, + /could not find a component/, + "Threw the correct error message" + ); }); diff --git a/tests/integration/components/reconcile-test.js b/tests/integration/components/reconcile-test.js index ab667b5..c2133ad 100644 --- a/tests/integration/components/reconcile-test.js +++ b/tests/integration/components/reconcile-test.js @@ -1,24 +1,24 @@ -import $ from 'jquery'; -import Ember from 'ember'; -import { moduleForComponent, test } from 'ember-qunit'; -import wait from 'ember-test-helpers/wait'; -import hbs from 'htmlbars-inline-precompile'; +import $ from "jquery"; +import Ember from "ember"; +import { moduleForComponent, test } from "ember-qunit"; +import wait from "ember-test-helpers/wait"; +import hbs from "htmlbars-inline-precompile"; import { pleaseDontUseThisExportToGetTheEmberIslandsInstance as getInstance, - reconcile -} from 'ember-islands'; + reconcile, +} from "ember-islands"; const { run } = Ember; -moduleForComponent('ember-islands', 'Integration | Component | rerendering', { +moduleForComponent("ember-islands", "Integration | Component | rerendering", { integration: true, beforeEach() { this.testContainer = $(''); - $('#ember-testing').append(this.testContainer); - } + $("#ember-testing").append(this.testContainer); + }, }); -test('when the DOM does not change', function(assert) { +test("when the DOM does not change", function (assert) { this.testContainer.html(`