Skip to content

Commit

Permalink
Merge pull request #35 from posthtml/jscs
Browse files Browse the repository at this point in the history
feat(lint): own jscs config
  • Loading branch information
voischev committed Sep 22, 2015
2 parents 6238d48 + f0576f9 commit 6b4b203
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 22 deletions.
22 changes: 20 additions & 2 deletions .jscsrc
@@ -1,5 +1,4 @@
{
"plugins": ["jscs-protein"],
"excludeFiles": [
".git/**",
"node_modules/**",
Expand All @@ -10,5 +9,24 @@
"esnext": true,
"requireArrowFunctions": true,
"requireShorthandArrowFunctions": true,
"requireTemplateStrings": true
"requireTemplateStrings": true,
"disallowSpacesInCallExpression": true,
"disallowSpaceAfterObjectKeys": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowMultipleLineBreaks": true,
"requireSemicolons": true,
"requireFunctionDeclarations": true,
"requireCommaBeforeLineBreak": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"disallowSpacesInFunction": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInConditionalExpression": {
"afterTest": true,
"afterConsequent": true
}
}
1 change: 0 additions & 1 deletion gulpfile.babel.js
Expand Up @@ -34,7 +34,6 @@ gulp.task('build:package', () => {

gulp.task('build', ['build:lib', 'build:docs', 'build:package']);


// Changelog

gulp.task('changelog', done => {
Expand Down
9 changes: 4 additions & 5 deletions lib/api.js
Expand Up @@ -17,7 +17,7 @@ export default {
* return tree;
* }
*/
walk: function (cb) {
walk: function walk(cb) {
return traverse(this, node => cb(node));
},
/**
Expand All @@ -36,7 +36,7 @@ export default {
* return tree;
* }
*/
match: function (precondition, cb) {
match: function match(precondition, cb) {
return this.walk(node => {
if(compare(precondition, node)) {
return cb(node);
Expand All @@ -59,7 +59,7 @@ export default {
* return tree;
* }
*/
eachClass: function(className, cb) {
eachClass: function eachClass(className, cb) {
return this.walk(node => {
let classes = node.attrs && node.attrs.class.split(' ') || [];
if(classes.includes(className)) {
Expand All @@ -70,8 +70,7 @@ export default {
}
};


function traverse (tree, cb) {
function traverse(tree, cb) {
if (Array.isArray(tree)) {
for (let i = 0, l = tree.length; i < l; i++) {
let item = tree[i];
Expand Down
16 changes: 8 additions & 8 deletions lib/parser.js
Expand Up @@ -8,7 +8,7 @@ export default {
* @param {String} html
* @return {Object}
*/
toTree: function (html) {
toTree: function toTree(html) {
let bufArray = [],
results = [];

Expand Down Expand Up @@ -81,7 +81,7 @@ export default {
* @param {Object} options Parse options
* @return {String} html string
*/
toHtml: function (tree, options = {}) {
toHtml: function toHtml(tree, options = {}) {

/**
* options parse
Expand Down Expand Up @@ -112,7 +112,7 @@ export default {

return html(tree);

function html (tree) {
function html(tree) {

if(typeof(tree) === 'string') {
return tree;
Expand Down Expand Up @@ -141,20 +141,20 @@ export default {
}
} else {
buf += `<${ tag }${
node.attrs ?
attrs(node.attrs) :
node.attrs?
attrs(node.attrs):
''
}>${
node.content ?
html(node.content) :
node.content?
html(node.content):
''
}</${ tag }>`;
}
});

return buf;

function attrs (obj) {
function attrs(obj) {
let attr = '';
for (let key in obj) {
attr += ` ${key}="${obj[key]}"`;
Expand Down
2 changes: 1 addition & 1 deletion lib/posthtml.js
Expand Up @@ -33,7 +33,7 @@ class Posthtml {
process(tree, options = {}) {
return new Promise(resolve => {

tree = options.skipParse ? tree : this.parse(tree);
tree = options.skipParse? tree: this.parse(tree);
tree.options = options;

for(let key in api) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -41,7 +41,6 @@
"gulp-json-editor": "^2.2.1",
"isparta": "^3.0.3",
"jscs": "^2.0.0",
"jscs-protein": "git://github.com/theprotein/jscs-protein.git#1d22e08ca767958a95b79f3bad6449fb2fa9f496",
"jshint": "^2.8.0",
"mocha": "^2.2.5",
"mversion": "^1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion test/options.js
Expand Up @@ -3,7 +3,7 @@ import posthtml from '../index.js';
import { expect } from 'chai';

const beforeHTML = '<div class="button"><rect/><div class="button__text">Text</div></div>';
const options = { singleTags : ['rect'], closingSingleTag: 'slash' };
const options = { singleTags: ['rect'], closingSingleTag: 'slash' };

function test(html, done) {
posthtml().process(html, options).then(result => {
Expand Down
6 changes: 3 additions & 3 deletions test/plugins.js
Expand Up @@ -50,7 +50,7 @@ describe('Plugins', () => {
});

it('set options skipParse', done => {
testPluginsArray(tree, { skipParse : true }, done);
testPluginsArray(tree, { skipParse: true }, done);
});

});
Expand All @@ -62,7 +62,7 @@ describe('Plugins', () => {
});

it('set options skipParse', done => {
testPluginUse(tree, { skipParse : true }, done);
testPluginUse(tree, { skipParse: true }, done);
});

});
Expand All @@ -71,7 +71,7 @@ describe('Plugins', () => {
let html = '<div class="cls"><br><rect></div>';
let ref = '<div class="cls"><br/><rect/></div>';

function plugin (tree) {
function plugin(tree) {
tree.options.singleTags = ['rect'];
tree.options.closingSingleTag = 'slash';
return tree;
Expand Down

0 comments on commit 6b4b203

Please sign in to comment.