Skip to content

Commit

Permalink
Merge pull request #1 from zxqfox/hotfix/code-climate
Browse files Browse the repository at this point in the history
Code climate fixes
  • Loading branch information
qfox committed Nov 30, 2014
2 parents f9d8c39 + a101e1e commit c3d00c4
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ test-make-temp/
lib-cov/
coverage.html
.DS_Store
*.sublime*
*.sublime*
/html-report
36 changes: 20 additions & 16 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"preset": "yandex",
"preset": "yandex",

"additionalRules": [
"node_modules/jscs-jsdoc/lib/rules/*.js"
],
"jsDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true,
"checkReturnTypes": true,
"requireReturnTypes": true,
"checkTypes": true,
"checkRedundantReturns": true,
"checkRedundantAccess": true,
"leadingUnderscoreAccess": "private",
"enforceExistence": true
}
"plugins": [
"jscs-jsdoc"
],
"jsDoc": {
"checkAnnotations": {
"preset": "closurecompiler",
"extra": {"api": false, "test": true}
},
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true,
"checkReturnTypes": true,
"requireReturnTypes": true,
"checkTypes": "strictNativeCase",
"checkRedundantReturns": true,
"checkRedundantAccess": true,
"leadingUnderscoreAccess": "private",
"enforceExistence": true
}
}
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ node_js:
- "0.10"
- "0.11"

matrix:
allow_failures:
- node_js: "0.11"
script: npm run travis
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require(process.env.PYM_COVER === '1' ? './lib-cov/pym' : './lib/pym');
49 changes: 27 additions & 22 deletions lib/pym.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ App.create = function create(opts) {

/**
* App constructor
* @constructor
* @class App
* @param {Object} opts
* @param {String} opts.path
* @param {string} opts.path
*/
function App(opts) {
opts = opts || {};
Expand All @@ -40,18 +40,18 @@ function App(opts) {
* @api
* @param {string[]} dependencies
* @param {function(...[resolvedDependency])} successCallbackFunction
* @param {function(error: Error)} [errorCallbackFunction]
* @param {function(Error)} [errorCallbackFunction]
*/
this.require = ym.require;

/**
* Loads node package with module provisions
* @api
* @param {String|String[]|Object|Function} package - package name, or list of,
* @param {(string|string[]|Object|Function)} package - package name, or list of,
* or package object, or package function
* @returns {PYM} this
*/
this.usePackage = function use(package, options) {
this.usePackage = function usePackage(package, options) {
options = options || {};

var resolvedPackage = _resolvePackageSync(path, package);
Expand All @@ -60,14 +60,19 @@ function App(opts) {
return this;
};

// this.meta = function (package) {
// };

// load required modules if passed
if (opts.uses) {
opts.uses.forEach(function (plugin) {
this.use(plugin);
}, this);
if (Array.isArray(opts.uses)) {
opts.uses.forEach(function (plugin) {
this.usePackage(plugin);
}, this);
} else if (typeof opts.uses === 'object') {
Object.keys(opts.uses).forEach(function (key) {
this.usePackage(key, opts.uses[key]);
}, this);
} else {
throw new Error('Unsupported value in uses property');
}
}
}

Expand Down Expand Up @@ -140,12 +145,12 @@ function _wrapToArchitect(setup, metadata) {
* @private
* @param {Function} provide - `ym` `provide` function in define ctx
* @param {Object} cached - cached result of the last `register` call
* @param {String} service - required `service` name (module name in `ym`)
* @param {string} service - required `service` name (module name in `ym`)
*/
function _provideService(provide, cached, service) {
if (cached.err) {
provide(null, cached.err);
} else if (!cached.result[service]) {
} else if (!cached.result || !cached.result[service]) {
provide(null, new Error('Invalid architect plugin found on service ' + service));
} else {
provide(cached.result[service]);
Expand All @@ -155,7 +160,7 @@ function _wrapToArchitect(setup, metadata) {

/**
* @private
* @param {String[]} keys
* @param {string[]} keys
* @param {Array} values
* @returns {Object}
* @test [["a","b"],["A","B"]] >>> {"a":"A","b":"B"}
Expand All @@ -176,13 +181,13 @@ var dirname = PATH.dirname;
* Loads a module, getting metadata from either it's package.json
* or export object.
* @private
* @param {String} base
* @param {String} relativePath
* @param {string} base
* @param {string} relativePath
* @returns {Object}
* - {String[]} provides
* - {String[]} consumes
* - {String} packagePath
* - {String}
* - {string[]} provides
* - {string[]} consumes
* - {string} packagePath
* - {string}
*/
function _resolvePackageSync(base, relativePath) {
var packageJsonPath;
Expand Down Expand Up @@ -249,8 +254,8 @@ var realpathSync = FS.realpathSync;
* It's not the full node require system algorithm, but it's the 99% case
* This throws, make sure to wrap in try..catch
* @private
* @param {String} base - base path
* @param {String} relativePath
* @param {string} base - base path
* @param {string} relativePath
*/
function _resolvePackagePathSync(base, relativePath) {
var originalBase = base;
Expand Down
22 changes: 15 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"engines": {
"node": ">= 0.10"
},
"main": "lib/pym.js",
"main": "index.js",
"files": [
"lib",
"LICENSE"
Expand All @@ -30,14 +30,22 @@
"ym": "0.1.x"
},
"devDependencies": {
"jscs": "1.6.x",
"jscs-jsdoc": "0.0.12",
"jshint": "~2.5.5",
"mocha": "~1.14.0"
"istanbul": "^0.3.2",
"istanbul-coveralls": "1.0.x",
"jscs": "1.8.x",
"jscs-jsdoc": "0.2.x",
"jshint": "~2.5.10",
"mocha": "~2.0.1",
"mocha-istanbul": "*"
},
"scripts": {
"lint": "./node_modules/.bin/jshint lib test && ./node_modules/.bin/jscs lib test",
"test": "npm run lint && ./node_modules/.bin/mocha"
"cov-clean": "rm -rf lib-cov; rm -rf html-report",
"cov-build": "istanbul instrument --output lib-cov --no-compact --variable global.__coverage__ lib",
"cov": "npm run cov-clean && npm run cov-build && PYM_COVER=1 mocha -R mocha-istanbul",
"lint": "jshint lib test && jscs lib test",
"test": "npm run lint && mocha",
"travis": "npm run test && npm run coveralls",
"coveralls": "istanbul cover ./node_modules/.bin/_mocha -- -R spec && istanbul-coveralls"
},
"licenses": [
{
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/modules/architect-imports-abc/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Example of architect api plugin
* @param {Object} options
* @param {Object} imports
* @param {function(Error, Object)} register
*/
module.exports = function (options, imports, register) {
register(null, {
'imports-abc': {
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/modules/architect-invalid-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Example of invalid architect api plugin
* @param {Object} options
* @param {Object} imports
* @param {function(Error, Object)} register
*/
module.exports = function (options, imports, register) {
if (options.throwError) {
register(new Error('invalid plugin error'));
} else if (options.returnInvalidString) {
register(null, 'invalid');
} else if (options.multipleTimes) {
register(null, {
config: '1'
});
register(null, {
config: '2'
});
}
};
8 changes: 8 additions & 0 deletions test/fixtures/modules/architect-invalid-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "architect-imports-abc",
"version": "0.0.1",
"main": "index.js",
"plugin": {
"provides": ["invalid"]
}
}
6 changes: 6 additions & 0 deletions test/fixtures/modules/architect-multiple-registers/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
var alreadyCalled = false;

/**
* Example of architect api plugin
* @param {Object} options
* @param {Object} imports
* @param {function(Error, Object)} register
*/
module.exports = function (options, imports, register) {
if (alreadyCalled) {
throw new Error('Redundant setup call for architect plugin');
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/modules/architect-plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Example of architect api plugin
* @param {Object} options
* @param {Object} imports
* @param {function(Error, Object)} register
*/
module.exports = function (options, imports, register) {
register(null, {
service: {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/modules/modules-abc/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Example of plugin
* @param {YM} ym
*/
module.exports = function (ym) {
ym.define('a', function (provide) {
provide('a');
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/modules/some-config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Stub
*/
module.exports = function () {
throw new Error('Shouldn\'t be executed');
};
5 changes: 5 additions & 0 deletions test/fixtures/modules/some-config/index.ym.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Example of exporting module
* @param {YM} ym
* @param {Object} options
*/
module.exports = function (ym, options) {
ym.define('config', function (provide) {
provide({
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--reporter spec
--timeout 10
--timeout 20
--growl

0 comments on commit c3d00c4

Please sign in to comment.