Skip to content

Commit

Permalink
Merge pull request #44 from ember-cli/linting
Browse files Browse the repository at this point in the history
Linting + Prettier
  • Loading branch information
rwjblue authored Oct 8, 2017
2 parents c0211b5 + c055d86 commit cccb6d2
Show file tree
Hide file tree
Showing 9 changed files with 862 additions and 59 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
extends: ['eslint:recommended', 'prettier'],
plugins: ['prettier'],
parserOptions: {
ecmaVersion: 2017,
},
env: {
node: true,
},
rules: {
'prettier/prettier': ['error', { singleQuote: true, trailingComma: 'es5' }],
},
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"devDependencies": {
"broccoli-test-helper": "^1.1.0",
"co": "^4.6.0",
"mocha": "^3.3.0"
"eslint-config-prettier": "^2.6.0",
"eslint-plugin-prettier": "^2.3.1",
"mocha": "^3.3.0",
"mocha-eslint": "^4.1.0",
"prettier": "^1.7.4"
},
"files": [
"src",
Expand Down
6 changes: 5 additions & 1 deletion src/bower-dependency-version-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class BowerDependencyVersionChecker extends DependencyVersionChecker {

let addon = this._parent._addon;
let project = addon.project;
let bowerDependencyPath = path.join(project.root, project.bowerDirectory, this.name);
let bowerDependencyPath = path.join(
project.root,
project.bowerDirectory,
this.name
);

this._jsonPath = path.join(bowerDependencyPath, '.bower.json');
this._fallbackJsonPath = path.join(bowerDependencyPath, 'bower.json');
Expand Down
7 changes: 4 additions & 3 deletions src/dependency-version-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ class DependencyVersionChecker {
let message = _message;

if (!message) {
message = 'The addon `' + this._parent._addon.name + '` requires the ' + this._type + ' package ' +
'`' + this.name + '` to be above ' + compareVersion + ', but you have ' + this.version + '.';
message = `The addon \`${this._parent._addon.name}\` requires the ${this
._type} package \`${this
.name}\` to be above ${compareVersion}, but you have ${this.version}.`;
}

if (!this.isAbove(compareVersion)) {
let error = new Error(message);
let error = new Error(message);

error.suppressStacktrace = true;

Expand Down
7 changes: 4 additions & 3 deletions src/npm-dependency-version-checker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const path = require('path');
const resolve = require('resolve');
const DependencyVersionChecker = require('./dependency-version-checker');

Expand All @@ -12,8 +11,10 @@ class NPMDependencyVersionChecker extends DependencyVersionChecker {

let jsonPath;
try {
jsonPath = resolve.sync(this.name + '/package.json', { basedir: addon.root });
} catch(e) {
jsonPath = resolve.sync(this.name + '/package.json', {
basedir: addon.root,
});
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
jsonPath = null;
} else {
Expand Down
5 changes: 5 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: {
mocha: true,
}
};
94 changes: 50 additions & 44 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ function buildPackage(name, version) {
}

function buildBowerPackage(name, version, disableBowerVersion) {

return {
'.bower.json': disableBowerVersion ? `{"name": "${name}"}` : buildPackageJSON(name, version),
'bower.json': buildPackageJSON(name, version)
'.bower.json': disableBowerVersion
? `{"name": "${name}"}`
: buildPackageJSON(name, version),
'bower.json': buildPackageJSON(name, version),
};
}

Expand All @@ -34,30 +35,32 @@ describe('ember-cli-version-checker', function() {

class FakeAddon {
constructor(project) {
this.root = projectRoot.path('node_modules/fake-addon'),
this.project = project || {
root: projectRoot.path(),
bowerDirectory: 'bower_components'
};
(this.root = projectRoot.path('node_modules/fake-addon')),
(this.project = project || {
root: projectRoot.path(),
bowerDirectory: 'bower_components',
});
this.name = 'fake-addon';
}
}

beforeEach(co.wrap(function* () {
projectRoot = yield createTempDir();
}));
beforeEach(
co.wrap(function*() {
projectRoot = yield createTempDir();
})
);

describe('VersionChecker#forEmber', function() {
let addon, checker, projectContents;

beforeEach(function() {
projectContents = {
'bower_components': {
'ember': buildBowerPackage('ember', '1.13.2')
bower_components: {
ember: buildBowerPackage('ember', '1.13.2'),
},
node_modules: {
'ember-source': buildPackage('ember-source', '2.10.0'),
},
'node_modules': {
'ember-source': buildPackage('ember-source', '2.10.0')
}
};

addon = new FakeAddon();
Expand Down Expand Up @@ -86,12 +89,12 @@ describe('ember-cli-version-checker', function() {
let addon, checker;
beforeEach(function() {
projectRoot.write({
'bower_components': {
'ember': buildBowerPackage('ember', '1.12.1')
bower_components: {
ember: buildBowerPackage('ember', '1.12.1'),
},
node_modules: {
ember: buildPackage('ember', '2.0.0'),
},
'node_modules': {
'ember': buildPackage('ember', '2.0.0')
}
});

addon = new FakeAddon();
Expand All @@ -106,14 +109,14 @@ describe('ember-cli-version-checker', function() {
describe('nested packages', function() {
it('finds nested packages from the current addons root', function() {
projectRoot.write({
'node_modules': {
'bar': buildPackage('bar', '3.0.0'),
node_modules: {
bar: buildPackage('bar', '3.0.0'),
'fake-addon': {
'node_modules': {
'bar': buildPackage('bar', '2.0.0')
}
}
}
node_modules: {
bar: buildPackage('bar', '2.0.0'),
},
},
},
});

addon.root = projectRoot.path('node_modules/fake-addon');
Expand Down Expand Up @@ -161,9 +164,9 @@ describe('ember-cli-version-checker', function() {

it('can return a fallback bower version for non-tagged releases', function() {
projectRoot.write({
'bower_components': {
'ember': buildBowerPackage('ember', '1.13.2', true)
}
bower_components: {
ember: buildBowerPackage('ember', '1.13.2', true),
},
});

let thing = checker.for('ember', 'bower');
Expand Down Expand Up @@ -226,9 +229,9 @@ describe('ember-cli-version-checker', function() {

it('returns true on beta releases if version is above the specified range', function() {
projectRoot.write({
'bower_components': {
'ember': buildBowerPackage('ember', '2.3.0-beta.2+41030996', true)
}
bower_components: {
ember: buildBowerPackage('ember', '2.3.0-beta.2+41030996', true),
},
});

let thing = checker.for('ember', 'bower');
Expand All @@ -238,9 +241,9 @@ describe('ember-cli-version-checker', function() {

it('returns false on beta releases if version is below the specified range', function() {
projectRoot.write({
'bower_components': {
'ember': buildBowerPackage('ember', '2.3.0-beta.2+41030996', true)
}
bower_components: {
ember: buildBowerPackage('ember', '2.3.0-beta.2+41030996', true),
},
});

let thing = checker.for('ember', 'bower');
Expand Down Expand Up @@ -399,7 +402,8 @@ describe('ember-cli-version-checker', function() {
describe('assertAbove', function() {
it('throws an error with a default message if a matching version was not found', function() {
let thing = checker.for('ember', 'npm');
let message = 'The addon `fake-addon` requires the npm package `ember` to be above 999.0.0, but you have 2.0.0.';
let message =
'The addon `fake-addon` requires the npm package `ember` to be above 999.0.0, but you have 2.0.0.';

assert.throws(function() {
thing.assertAbove('999.0.0');
Expand All @@ -419,13 +423,15 @@ describe('ember-cli-version-checker', function() {
let message = 'Must use at least Ember CLI 0.1.2 to use xyz feature';
let thing = checker.for('ember', 'npm');

assert.throws(function() {
thing.assertAbove('999.0.0', message);
},
assert.throws(
function() {
thing.assertAbove('999.0.0', message);
},

function(err) {
return err.suppressStacktrace;
});
function(err) {
return err.suppressStacktrace;
}
);
});
});
});
Expand Down
8 changes: 8 additions & 0 deletions tests/lint-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const paths = ['src', 'tests', 'index.js', '.eslintrc.js'];

require('mocha-eslint')(paths, {
timeout: 10000,
slow: 1000,
});
Loading

0 comments on commit cccb6d2

Please sign in to comment.