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

chore(follow eslint with ember-suave) #47

Merged
merged 1 commit into from Aug 26, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc.js
Expand Up @@ -4,10 +4,18 @@ module.exports = {
ecmaVersion: 2017,
sourceType: 'module'
},
extends: 'eslint:recommended',
extends: [
'eslint:recommended',
'plugin:ember-suave/recommended'
],
env: {
browser: true
},
rules: {
'quotes': ['error', 'single', { 'allowTemplateLiterals': true, 'avoidEscape': true }],
'ember-suave/no-const-outside-module-scope': 0,
'ember-suave/no-direct-property-access': 1,
'ember-suave/require-access-in-comments': 0,
'prefer-const': 2,
}
};
3 changes: 2 additions & 1 deletion addon/-debug/helpers.js
@@ -1,4 +1,5 @@
import Ember from 'ember';
const { Logger } = Ember;

export function assert(msg, conditional) {
if (!conditional) {
Expand All @@ -7,7 +8,7 @@ export function assert(msg, conditional) {
}

export function debug() {
Ember.Logger.debug(...arguments);
Logger.debug(...arguments);
}

export function debugOnError(msg, conditional) {
Expand Down
39 changes: 19 additions & 20 deletions addon/components/ember-attacher-inner.js
Expand Up @@ -44,10 +44,10 @@ export default Component.extend({
this._hideListenersOnTargetByEvent = {};

// Hacks to make sure event listeners have the right context and are still cancellable later
this._hideIfMouseOutsideTargetOrAttachment =
this._hideIfMouseOutsideTargetOrAttachment.bind(this);
this._debouncedHideIfMouseOutsideTargetOrAttachment =
this._debouncedHideIfMouseOutsideTargetOrAttachment.bind(this);
this._hideIfMouseOutsideTargetOrAttachment
= this._hideIfMouseOutsideTargetOrAttachment.bind(this);
this._debouncedHideIfMouseOutsideTargetOrAttachment
= this._debouncedHideIfMouseOutsideTargetOrAttachment.bind(this);
this._hideOnLostFocus = this._hideOnLostFocus.bind(this);
this._hideOnMouseLeaveTarget = this._hideOnMouseLeaveTarget.bind(this);
this._hideAfterDelay = this._hideAfterDelay.bind(this);
Expand All @@ -66,7 +66,7 @@ export default Component.extend({

this._currentTarget = target;

showOn.forEach(event => {
showOn.forEach((event) => {
this._showListenersOnTargetByEvent[event] = this._showAfterDelay;

target.addEventListener(event, this._showAfterDelay);
Expand All @@ -89,8 +89,8 @@ export default Component.extend({
}

[this._hideListenersOnTargetByEvent, this._showListenersOnTargetByEvent]
.forEach(eventToListener => {
Object.keys(eventToListener).forEach(event => {
.forEach((eventToListener) => {
Object.keys(eventToListener).forEach((event) => {
target.removeEventListener(event, eventToListener[event]);
});
});
Expand Down Expand Up @@ -127,12 +127,11 @@ export default Component.extend({
cancel(this._isVisibleTimeout);

if (delay) {
this._isVisibleTimeout =
later(this, () => {
if (!this.isDestroyed && !this.isDestroying) {
this.set('isVisible', isVisible);
}
}, delay);
this._isVisibleTimeout = later(this, () => {
if (!this.isDestroyed && !this.isDestroying) {
this.set('isVisible', isVisible);
}
}, delay);
} else {
this.set('isVisible', isVisible);
}
Expand Down Expand Up @@ -241,22 +240,22 @@ export default Component.extend({
const target = this.get('target');

if (hideOn.indexOf('click') !== -1) {
const showOnClickListener = this._showListenersOnTargetByEvent['click'];
const showOnClickListener = this._showListenersOnTargetByEvent.click;

if (showOnClickListener) {
target.removeEventListener('click', showOnClickListener);

delete this._showListenersOnTargetByEvent['click'];
delete this._showListenersOnTargetByEvent.click;
}

this._hideListenersOnTargetByEvent['click'] = this._hideAfterDelay;
this._hideListenersOnTargetByEvent.click = this._hideAfterDelay;
target.addEventListener('click', this._hideAfterDelay);
}

// Hides the attachment when the mouse leaves the target
// (or leaves both target and attachment for interactive attachments)
if (hideOn.indexOf('mouseleave') !== -1) {
this._hideListenersOnTargetByEvent['mouseleave'] = this._hideOnMouseLeaveTarget;
this._hideListenersOnTargetByEvent.mouseleave = this._hideOnMouseLeaveTarget;
target.addEventListener('mouseleave', this._hideOnMouseLeaveTarget);
}

Expand Down Expand Up @@ -408,14 +407,14 @@ export default Component.extend({

// Switch clicking back to a show event
if (showOn.indexOf('click') !== -1) {
const hideOnClickListener = this._hideListenersOnTargetByEvent['click'];
const hideOnClickListener = this._hideListenersOnTargetByEvent.click;

if (hideOnClickListener) {
target.removeEventListener('click', hideOnClickListener);
delete this._hideListenersOnTargetByEvent['click'];
delete this._hideListenersOnTargetByEvent.click;
}

this._showListenersOnTargetByEvent['click'] = this._showAfterDelay;
this._showListenersOnTargetByEvent.click = this._showAfterDelay;
target.addEventListener('click', this._showAfterDelay);
}

Expand Down
12 changes: 6 additions & 6 deletions addon/components/ember-attacher.js
Expand Up @@ -89,13 +89,13 @@ export default Component.extend({

this.id = this.id || generateGuid();

let options = getOwner(this).resolveRegistration('config:environment').emberAttacher;
const options = getOwner(this).resolveRegistration('config:environment').emberAttacher;

// If no emberAttacher hash was found, do nothing
if (options) {
let attrs = this.get('attrs') || {};
const attrs = this.get('attrs') || {};

for (let key in options) {
for (const key in options) {
stripInProduction(() => {
if (!DEFAULTS.hasOwnProperty(key)) {
warn(`Unknown property given as an ember-attacher default: ${key}`, { id: 700152 });
Expand All @@ -112,9 +112,9 @@ export default Component.extend({

_modifiers: computed('arrow', 'flip', 'modifiers', function() {
// Deep copy the modifiers since we might write to the provided hash
let modifiers = this.get('modifiers') ? JSON.parse(JSON.stringify(this.get('modifiers'))) : {};
const modifiers = this.get('modifiers') ? JSON.parse(JSON.stringify(this.get('modifiers'))) : {};

let arrow = this.get('arrow');
const arrow = this.get('arrow');
if (typeof(arrow) === 'boolean') {
if (!modifiers.arrow) {
modifiers.arrow = { enabled: arrow };
Expand All @@ -123,7 +123,7 @@ export default Component.extend({
}
}

let flipString = this.get('flip');
const flipString = this.get('flip');
if (flipString) {
if (!modifiers.flip) {
modifiers.flip = { behavior: flipString.split(' ') };
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -33,7 +33,8 @@
"ember-cli-htmlbars": "^2.0.2",
"ember-cli-sass": "^7.0.0",
"ember-popper": "^0.6.0",
"ember-truth-helpers": "^1.3.0"
"ember-truth-helpers": "^1.3.0",
"eslint-plugin-ember-suave": "^1.0.0"
},
"devDependencies": {
"@html-next/flexi-config": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/services/popover-data.js
Expand Up @@ -13,5 +13,5 @@ export default Service.extend({
showDelay: 0,
showDuration: 300,
showOn: 'click',
target: '.target-plz',
target: '.target-plz'
});
2 changes: 1 addition & 1 deletion tests/dummy/app/services/tooltip-data.js
Expand Up @@ -12,5 +12,5 @@ export default Service.extend({
renderInPlace: false,
showDelay: 0,
showDuration: 300,
showOn: 'mouseenter focus',
showOn: 'mouseenter focus'
});
2 changes: 1 addition & 1 deletion tests/helpers/module-for-acceptance.js
Expand Up @@ -14,7 +14,7 @@ export default function(name, options = {}) {
},

afterEach() {
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
const afterEach = options.afterEach && options.afterEach.apply(this, arguments);
return RSVP.resolve(afterEach).then(() => destroyApp(this.application));
}
});
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/start-app.js
Expand Up @@ -8,7 +8,7 @@ export default function startApp(attrs) {
attributes = merge(attributes, attrs); // use defaults, but you can override;

return run(() => {
let application = Application.create(attributes);
const application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
return application;
Expand Down
Expand Up @@ -31,7 +31,7 @@ test('hides when the target loses focus', function(assert) {
return click(find('#click-toggle')).then(() => {
assert.equal(innerAttacher.style.display, '', 'Now shown');

document.getElementById("focus-me").focus();
document.getElementById('focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, 'none', 'hidden again');
Expand Down Expand Up @@ -63,7 +63,7 @@ test('with interactive=false: hides when the attachment gains focus', function(a
return click(find('#click-toggle')).then(() => {
assert.equal(innerAttacher.style.display, '', 'Now shown');

document.getElementById("attachment-focus-me").focus();
document.getElementById('attachment-focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, 'none', 'hidden again');
Expand Down Expand Up @@ -96,12 +96,12 @@ test("with interactive=true: doesn't hide when the attachment gains focus", func
return click(find('#click-toggle')).then(() => {
assert.equal(innerAttacher.style.display, '', 'Now shown');

document.getElementById("attachment-focus-me").focus();
document.getElementById('attachment-focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, '', 'Still shown');

document.getElementById("outer-focus-me").focus();
document.getElementById('outer-focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, '', 'Hidden again');
Expand Down
Expand Up @@ -31,7 +31,7 @@ test('hides when the target loses focus', function(assert) {
return click(find('#click-toggle')).then(() => {
assert.equal(innerAttacher.style.display, '', 'Now shown');

document.getElementById("focus-me").focus();
document.getElementById('focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, 'none', 'hidden again');
Expand Down Expand Up @@ -63,7 +63,7 @@ test('with interactive=false: hides when the attachment gains focus', function(a
return click(find('#click-toggle')).then(() => {
assert.equal(innerAttacher.style.display, '', 'Now shown');

document.getElementById("attachment-focus-me").focus();
document.getElementById('attachment-focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, 'none', 'hidden again');
Expand Down Expand Up @@ -96,12 +96,12 @@ test("with interactive=true: doesn't hide when the attachment gains focus", func
return click(find('#click-toggle')).then(() => {
assert.equal(innerAttacher.style.display, '', 'Now shown');

document.getElementById("attachment-focus-me").focus();
document.getElementById('attachment-focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, '', 'Still shown');

document.getElementById("outer-focus-me").focus();
document.getElementById('outer-focus-me').focus();

return wait().then(() => {
assert.equal(innerAttacher.style.display, '', 'Hidden again');
Expand Down
Expand Up @@ -96,7 +96,7 @@ test('nested attachers open and close as expected', function(assert) {

this.setProperties({
childIsShown: false,
parentIsShown: false,
parentIsShown: false
});

this.render(hbs`
Expand Down
12 changes: 11 additions & 1 deletion yarn.lock
Expand Up @@ -2198,7 +2198,7 @@ ember-cli-htmlbars@^1.1.1:
json-stable-stringify "^1.0.0"
strip-bom "^2.0.0"

ember-cli-htmlbars@^2.0.0, ember-cli-htmlbars@^2.0.1, ember-cli-htmlbars@^2.0.3:
ember-cli-htmlbars@^2.0.0, ember-cli-htmlbars@^2.0.1, ember-cli-htmlbars@^2.0.2, ember-cli-htmlbars@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/ember-cli-htmlbars/-/ember-cli-htmlbars-2.0.3.tgz#e116e1500dba12f29c94b05b9ec90f52cb8bb042"
dependencies:
Expand Down Expand Up @@ -2751,6 +2751,12 @@ escape-string-regexp@^1.0.0, escape-string-regexp@^1.0.2, escape-string-regexp@^
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

eslint-plugin-ember-suave@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-ember-suave/-/eslint-plugin-ember-suave-1.0.0.tgz#ea7d232a126562dcd8b1ee3aa2700ac3b626e514"
dependencies:
requireindex "~1.1.0"

eslint-scope@^3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8"
Expand Down Expand Up @@ -5374,6 +5380,10 @@ require-uncached@^1.0.3:
caller-path "^0.1.0"
resolve-from "^1.0.0"

requireindex@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.1.0.tgz#e5404b81557ef75db6e49c5a72004893fe03e162"

requires-port@1.x.x:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
Expand Down