Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Add coding standard and update code to comply.
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthierm committed May 2, 2016
1 parent 247d7c5 commit c519732
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 18 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false
59 changes: 59 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"esnext": false,
"disallowSpacesInsideArrayBrackets": "all",
"disallowMultipleVarDecl": true,
"requireSpaceBeforeObjectValues": true,
"requireCommaBeforeLineBreak": true,
"requireBlocksOnNewline": 1,
"disallowKeywordsOnNewLine": ["else"],
"disallowNewlineBeforeBlockStatements": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"disallowSpacesInCallExpression": true,
"disallowSpacesInsideParentheses": true,
"disallowEmptyBlocks": true,
"requireSpacesInsideObjectBrackets": "all",
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireLineFeedAtFileEnd": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"requireSpaceBeforeBlockStatements": true,
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateParameterSeparator": ", ",
"validateQuoteMarks": {
"mark": "'",
"escape": true
},
"requireSpaceBeforeKeywords": [
"else",
"while",
"catch"
],
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"while",
"with",
"return"
],
"requireSpaceBetweenArguments": true,
"requireSpaceAfterLineComment": true
}
27 changes: 27 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"browser": false,
"boss": true,
"curly": true,
"debug": false,
"devel": true,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": true,
"strict": false,
"white": false,
"eqnull": true,
"unused": true
}
3 changes: 1 addition & 2 deletions lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
var fs = require('fs');
var gutil = require('gulp-util');
var paths = require('./paths');
var utils = require('./utils');
var flags = require('./flags');

function deleteFolderRecursive(path, progress) {
var files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function(file, index) {
files.forEach(function(file) {
var curPath = path + '/' + file;
if (fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath, progress);
Expand Down
6 changes: 3 additions & 3 deletions lib/phplint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

var gulp = require('gulp');
var gutil = require('gulp-util');
var Spawn = require('gulp-spawn');
var gulpSpawn = require('gulp-spawn');
var Stream = require('stream');

var paths = require('./paths');

var spawn = function() {
return Spawn({
return gulpSpawn({
cmd: 'php',
args: [ '-l' ]
});
Expand Down Expand Up @@ -45,7 +45,7 @@ var filter = function(error, err) {

this.push(file);
done();
}
};

return stream;
};
Expand Down
23 changes: 12 additions & 11 deletions lib/symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var paths = require('./paths');
* instead of installed PEAR packages
*/
var setup = function(err, progress, complete) {
fs.readdirSync(paths.packages).forEach(function(packageName, index) {
fs.readdirSync(paths.packages).forEach(function(packageName) {
var packageLinkPath = path.join(paths.packages, packageName);
if (fs.lstatSync(packageLinkPath).isSymbolicLink()) {
var packageRealPath = path.join(
Expand All @@ -25,16 +25,17 @@ var setup = function(err, progress, complete) {
'www'
);

if ( fs.existsSync(packageRealPath)
&& (
!fs.existsSync(packageLinkPath)
|| packageRealPath != fs.realpathSync(packageLinkPath)
if (fs.existsSync(packageRealPath) &&
(
!fs.existsSync(packageLinkPath) ||
packageRealPath !== fs.realpathSync(packageLinkPath)
)
) {
fs.unlinkSync(packageLinkPath);
fs.symlinkSync(packageRealPath, packageLinkPath);
if (progress) {
progress(packageName,
progress(
packageName,
packageLinkPath,
packageRealPath
);
Expand All @@ -55,7 +56,7 @@ var setup = function(err, progress, complete) {
var teardown = function(err, progress, complete) {
function getPathList(dir, cwd) {
var pathList = [];
fs.readdirSync(dir).forEach(function(packageName, index) {
fs.readdirSync(dir).forEach(function(packageName) {
var packageLinkPath = path.join(dir, packageName);
if (fs.lstatSync(packageLinkPath).isSymbolicLink()) {
// Need to get the relative path for git checkout
Expand All @@ -71,7 +72,7 @@ var teardown = function(err, progress, complete) {
function revert(pathList) {
var cmd = 'git checkout -- ' + pathList.join(' ');
var deferred = q.defer();
child_process.exec(cmd, {}, function(code, stdout, stderr) {
child_process.exec(cmd, {}, function() {
if (complete) {
complete();
}
Expand All @@ -91,7 +92,7 @@ module.exports = {
gutil.log(gutil.colors.blue('Restoring symlinks for www/packages:'));
return this.teardown(
err,
function (packageName, packageLinkPath, packageRealPath) {
function (packageName) {
gutil.log(gutil.colors.gray('..'), packageName);
},
function () {
Expand All @@ -104,7 +105,7 @@ module.exports = {
gutil.log(gutil.colors.blue('Updating symlinks for www/packages:'));
return setup(
null,
function (packageName, packageLinkPath, packageRealPath) {
function (packageName) {
gutil.log(gutil.colors.gray('..'), packageName);
},
function () {
Expand All @@ -118,7 +119,7 @@ module.exports = {
);
return teardown(
null,
function (packageName, packageLinkPath, packageRealPath) {
function (packageName) {
gutil.log(gutil.colors.gray('..'), packageName);
},
function () {
Expand Down
2 changes: 0 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var fs = require('fs');
var flags = require('./flags');
var symlinks = require('./symlinks');

module.exports = {
deleteIfExists: function (path) {
Expand Down

0 comments on commit c519732

Please sign in to comment.