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

[update] Adds DSC style linting #108

Merged
merged 2 commits into from
Apr 3, 2018
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 2 additions & 41 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,9 @@
module.exports = {
root: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly recommend against this. These are the Ember defaults, and most apps and addons adhere to them. If there are specific rules we need to add on top, we could do so or maybe even use the DSC plugin alongside these.

Copy link
Contributor Author

@yowainwright yowainwright Apr 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwwagner90 I will follow up with my team and add that to eslint-config-dollarshaveclub if it makes sense for DSC—per your recommendation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it makes sense for DSC, but it does make sense for this and your other popular, open source, Ember addons. They are used heavily by the community and have several active contributors. I think it would be preferential to keep the linting the same it has been, in line with the Ember community, here.

parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
'dollarshaveclub/ember'
],
env: {
browser: true
},
rules: {
},
overrides: [
// node files
{
files: [
'index.js',
'testem.js',
'ember-cli-build.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'app/**',
'addon/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
root: true
};
68 changes: 34 additions & 34 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import Mixin from '@ember/object/mixin';
import { get, computed } from '@ember/object';
import { inject } from '@ember/service';
import { getOwner } from '@ember/application';
import Mixin from '@ember/object/mixin'
import { get, computed } from '@ember/object'
import { inject } from '@ember/service'
import { getOwner } from '@ember/application'

export default Mixin.create({
scheduler: inject('scheduler'),
service: inject('router-scroll'),

isFastBoot: computed(function() {
const fastboot = getOwner(this).lookup('service:fastboot');
return fastboot ? fastboot.get('isFastBoot') : false;
isFastBoot: computed(function () {
const fastboot = getOwner(this).lookup('service:fastboot')
return fastboot ? fastboot.get('isFastBoot') : false
}),

willTransition(...args) {
this._super(...args);
willTransition (...args) {
this._super(...args)

if (get(this, 'isFastBoot')) { return; }
if (get(this, 'isFastBoot')) { return }

get(this, 'service').update();
get(this, 'service').update()
},

didTransition(transitions, ...args) {
this._super(transitions, ...args);
didTransition (transitions, ...args) {
this._super(transitions, ...args)

if (get(this, 'isFastBoot')) { return; }
if (get(this, 'isFastBoot')) { return }

this.get('scheduler').scheduleWork('afterContentPaint', () => {
this.updateScrollPosition(transitions);
});
this.updateScrollPosition(transitions)
})
},

updateScrollPosition(transitions) {
const lastTransition = transitions[transitions.length - 1];
const url = get(lastTransition, 'handler.router.currentURL');
const hashElement = url ? document.getElementById(url.split('#').pop()) : null;
updateScrollPosition (transitions) {
const lastTransition = transitions[transitions.length - 1]
const url = get(lastTransition, 'handler.router.currentURL')
const hashElement = url ? document.getElementById(url.split('#').pop()) : null

let scrollPosition;
let scrollPosition

if(url && url.indexOf('#') > -1 && hashElement) {
scrollPosition = { x: hashElement.offsetLeft, y: hashElement.offsetTop };
if (url && url.indexOf('#') > -1 && hashElement) {
scrollPosition = { x: hashElement.offsetLeft, y: hashElement.offsetTop }
} else {
scrollPosition = get(this, 'service.position');
scrollPosition = get(this, 'service.position')
}
const scrollElement = get(this, 'service.scrollElement');
const scrollElement = get(this, 'service.scrollElement')

const preserveScrollPosition = get(lastTransition, 'handler.controller.preserveScrollPosition');
const preserveScrollPosition = get(lastTransition, 'handler.controller.preserveScrollPosition')

if (!preserveScrollPosition) {
if ('window' === scrollElement) {
window.scrollTo(scrollPosition.x, scrollPosition.y);
} else if ('#' === scrollElement.charAt(0)) {
const element = document.getElementById(scrollElement.substring(1));
if (scrollElement === 'window') {
window.scrollTo(scrollPosition.x, scrollPosition.y)
} else if (scrollElement.charAt(0) === '#') {
const element = document.getElementById(scrollElement.substring(1))

if (element) {
element.scrollLeft = scrollPosition.x;
element.scrollTop = scrollPosition.y;
element.scrollLeft = scrollPosition.x
element.scrollTop = scrollPosition.y
}
}
}
}
});
},
})
56 changes: 28 additions & 28 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
'use strict'

const getChannelURL = require('ember-source-channel-url');
const getChannelURL = require('ember-source-channel-url')

module.exports = function() {
module.exports = function () {
return Promise.all([
getChannelURL('release'),
getChannelURL('beta'),
Expand All @@ -15,57 +15,57 @@ module.exports = function() {
name: 'ember-lts-2.12',
npm: {
devDependencies: {
'ember-source': '~2.12.0'
}
}
'ember-source': '~2.12.0',
},
},
},
{
name: 'ember-lts-2.16',
npm: {
devDependencies: {
'ember-source': '~2.16.0'
}
}
'ember-source': '~2.16.0',
},
},
},
{
name: 'ember-lts-2.18',
npm: {
devDependencies: {
'ember-source': '~2.18.0'
}
}
'ember-source': '~2.18.0',
},
},
},
{
name: 'ember-release',
npm: {
devDependencies: {
'ember-source': urls[0]
}
}
'ember-source': urls[0],
},
},
},
{
name: 'ember-beta',
npm: {
devDependencies: {
'ember-source': urls[1]
}
}
'ember-source': urls[1],
},
},
},
{
name: 'ember-canary',
npm: {
devDependencies: {
'ember-source': urls[2]
}
}
'ember-source': urls[2],
},
},
},
{
name: 'ember-default',
npm: {
devDependencies: {}
}
}
]
};
});
};
devDependencies: {},
},
},
],
}
})
}
8 changes: 4 additions & 4 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
'use strict'

module.exports = function(/* environment, appConfig */) {
return { };
};
module.exports = function (/* environment, appConfig */) {
return { }
}
14 changes: 7 additions & 7 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
'use strict'

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon')

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
module.exports = function (defaults) {
const app = new EmberAddon(defaults, {
// Add options here
});
})

/*
This build file specifies the options for the dummy test app of this
Expand All @@ -14,5 +14,5 @@ module.exports = function(defaults) {
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
};
return app.toTree()
}
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
'use strict'

module.exports = {
name: 'ember-router-scroll'
};
name: 'ember-router-scroll',
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "ember-router-scroll",
"version": "0.5.0",
"version": "0.6.0",
"description": "Scroll to top with preserved browser history scroll position",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "ember build",
"eslint": "eslint . --fix",
"lint:js": "eslint ./*.js addon addon-test-support app config lib server test-support tests",
"start": "ember serve",
"test": "ember try:each",
Expand Down Expand Up @@ -48,8 +49,8 @@
"ember-source": "~3.0.0",
"ember-source-channel-url": "^1.0.1",
"ember-try": "^0.2.23",
"eslint-plugin-ember": "^5.0.0",
"eslint-plugin-node": "^5.2.1",
"eslint": "^4.19.1",
"eslint-config-dollarshaveclub": "^3.1.0",
"loader.js": "^4.2.3"
},
"engines": {
Expand Down
18 changes: 7 additions & 11 deletions testem.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: [
'Chrome'
],
launch_in_dev: [
'Chrome'
],
launch_in_ci: ['Chrome'],
launch_in_dev: ['Chrome'],
browser_args: {
Chrome: {
mode: 'ci',
Expand All @@ -17,8 +13,8 @@ module.exports = {
'--disable-gpu',
'--headless',
'--remote-debugging-port=0',
'--window-size=1440,900'
].filter(Boolean)
}
}
};
'--window-size=1440,900',
].filter(Boolean),
},
},
}
22 changes: 11 additions & 11 deletions tests/acceptance/basic-functionality-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, click, currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit'
import { setupApplicationTest } from 'ember-qunit'
import { visit, click, currentURL } from '@ember/test-helpers'

module('Acceptance | basic functionality', function(hooks) {
setupApplicationTest(hooks);
module('Acceptance | basic functionality', function (hooks) {
setupApplicationTest(hooks)

test('The application should work when loading a page and clicking a link', async function(assert) {
await visit('/');
test('The application should work when loading a page and clicking a link', async function (assert) {
await visit('/')

await click('a[href="/next-page"]');
await click('a[href="/next-page"]')

assert.equal(currentURL(), '/next-page');
});
});
assert.equal(currentURL(), '/next-page')
})
})
16 changes: 8 additions & 8 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';
import Application from '@ember/application'
import Resolver from './resolver'
import loadInitializers from 'ember-load-initializers'
import config from './config/environment'

const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver
});
Resolver,
})

loadInitializers(App, config.modulePrefix);
loadInitializers(App, config.modulePrefix)

export default App;
export default App
4 changes: 2 additions & 2 deletions tests/dummy/app/resolver.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Resolver from 'ember-resolver';
import Resolver from 'ember-resolver'

export default Resolver;
export default Resolver
Loading