Skip to content

Commit

Permalink
replaced jshint with eslint for better style check
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Sep 7, 2014
1 parent 8cf045d commit a8f9ea5
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 126 deletions.
3 changes: 1 addition & 2 deletions .jshintignore → .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.git/
benchmark/implementations/
node_modules/
demo/
dist/
node_modules/
47 changes: 47 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
env:
node: true
browser: false

plugins:
- nodeca

rules:
block-scoped-var: 2
brace-style: [ 2, '1tbs', { allowSingleLine: true } ]
camelcase: 0
consistent-return: 2
consistent-this: [ 2, self ]
curly: [ 2, all ]
default-case: 2
eol-last: 2
eqeqeq: 2
guard-for-in: 2
handle-callback-err: 2
max-depth: [ 1, 3 ]
max-nested-callbacks: [ 1, 4 ]
# string can exceed 80 chars, but should not overflow github website :)
max-len: [ 2, 120, 1000 ]
no-alert: 2
no-bitwise: 2
no-comma-dangle: 2
no-console: 2
no-div-regex: 2
no-else-return: 2
no-eq-null: 2
no-floating-decimal: 2
no-lonely-if: 2
no-process-exit: 0
no-trailing-spaces: 2
no-underscore-dangle: 0
quotes: [ 2, single, avoid-escape ]
radix: 2
space-after-keywords: [ 2, always ] # Fixed in master
space-in-brackets: [ 1, always ]

# temporary
no-func-assign: 0

#
# Our custom rules
#
nodeca/indent: [ 2, spaces, 2 ]
82 changes: 0 additions & 82 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ demo: lint browserify


lint:
jshint . --show-non-errors
eslint ./


test: lint
Expand Down
9 changes: 4 additions & 5 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
/*eslint no-console:0*/

'use strict';

Expand All @@ -15,8 +16,8 @@ var IMPLS = [];


fs.readdirSync(IMPLS_DIRECTORY).sort().forEach(function (name) {
var file = path.join(IMPLS_DIRECTORY, name),
code = require(file);
var file = path.join(IMPLS_DIRECTORY, name);
var code = require(file);

IMPLS_PATHS[name] = file;
IMPLS.push({
Expand Down Expand Up @@ -67,9 +68,7 @@ fs.readdirSync(SAMPLES_DIRECTORY).sort().forEach(function (sample) {

onComplete: onComplete,

defer: !!impl.code.async,

fn: function (deferred) {
fn: function () {
impl.code.run(content.string);
return;
}
Expand Down
5 changes: 3 additions & 2 deletions benchmark/profile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

var fs = require('fs');
var path = require('path');
var Remarkable = require('../');

var md = new Remarkable();

var data = fs.readFileSync(__dirname +'/samples/lorem1.txt', 'utf8');
var data = fs.readFileSync(path.join(__dirname, '/samples/lorem1.txt', 'utf8'));

for (var i=0; i<20000; i++) {
for (var i = 0; i < 20000; i++) {
md.render(data);
}
8 changes: 4 additions & 4 deletions bin/remarkable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node

/*eslint no-console:0*/

'use strict';

Expand All @@ -17,13 +17,13 @@ var cli = new argparse.ArgumentParser({
addHelp: true
});

cli.addArgument(['file'], {
cli.addArgument([ 'file' ], {
help: 'File to read',
nargs: '?',
defaultValue: '-'
});

cli.addArgument(['-t', '--trace'], {
cli.addArgument([ '-t', '--trace' ], {
help: 'Show stack trace on error',
action: 'storeTrue'
});
Expand Down Expand Up @@ -56,7 +56,7 @@ readFile(options.file, 'utf8', function (error, input) {
var output, md;

if (error) {
if ('ENOENT' === error.code) {
if (error.code === 'ENOENT') {
console.error('File not found: ' + options.file);
process.exit(2);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ exports.isEmpty = isEmpty;
exports.skipEmptyLines = skipEmptyLines;
exports.skipSpaces = skipSpaces;
exports.skipChars = skipChars;
exports.getLines = getLines;
exports.getLines = getLines;
2 changes: 1 addition & 1 deletion lib/lexer_block/blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var getLines = require('../helpers').getLines;


module.exports = function blockquote(state, startLine, endLine, silent) {
var marker, nextLine, oldBMarks, lastLineEmpty, subState,
var nextLine, lastLineEmpty, subState,
rules_named = state.lexerBlock.rules_named,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
Expand Down
2 changes: 1 addition & 1 deletion lib/lexer_block/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ module.exports = function code(state, startLine, endLine, silent) {

state.line = nextLine;
return true;
};
};
9 changes: 4 additions & 5 deletions lib/lexer_block/fences.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var skipChars = require('../helpers').skipChars;
var getLines = require('../helpers').getLines;


module.exports =function fences(state, startLine, endLine, silent) {
module.exports = function fences(state, startLine, endLine, silent) {
var marker, len, params, nextLine, mem,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
Expand All @@ -35,7 +35,7 @@ module.exports =function fences(state, startLine, endLine, silent) {
// search end of block
nextLine = startLine;

do {
for (;;) {
nextLine++;

if (nextLine >= endLine) {
Expand Down Expand Up @@ -63,8 +63,7 @@ module.exports =function fences(state, startLine, endLine, silent) {

// found!
break;

} while (true);
}

if (silent) { return true; }

Expand All @@ -76,4 +75,4 @@ module.exports =function fences(state, startLine, endLine, silent) {

state.line = skipEmptyLines(state, nextLine + 1);
return true;
};
};
2 changes: 1 addition & 1 deletion lib/lexer_block/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ module.exports = function heading(state, startLine, endLine, silent) {

state.line = skipEmptyLines(state, ++startLine);
return true;
};
};
2 changes: 2 additions & 0 deletions lib/lexer_block/lheading.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = function lheading(state, startLine, endLine, silent) {

if (pos < max) { return false; }

if (silent) { return true; }

state.tokens.push({ type: 'heading_open', level: marker === 0x3D/* = */ ? 1 : 2 });
state.lexerInline.tokenize(state, state.bMarks[startLine], state.eMarks[startLine]);
state.tokens.push({ type: 'heading_close', level: marker === 0x3D/* = */ ? 1 : 2 });
Expand Down
4 changes: 1 addition & 3 deletions lib/lexer_block/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ var skipEmptyLines = require('../helpers').skipEmptyLines;


function bullet_item(state, startLine, endLine, silent) {
var marker, nextLine, start,
var marker, nextLine,
rules_named = state.lexerBlock.rules_named,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];

// TODO: supporting list with only one paragraph for now

start = pos;
if (pos > max) { return false; }

marker = state.src.charCodeAt(pos++);
Expand Down Expand Up @@ -79,4 +78,3 @@ module.exports = function list(state, startLine, endLine, silent) {
}
return false;
};

20 changes: 10 additions & 10 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ function unescapeMd(str) {
var rules = {};


rules.blockquote_open = function (state, token) {
rules.blockquote_open = function (state /*, token*/) {
state.result += '<blockquote>';
};
rules.blockquote_close = function (state, token) {
rules.blockquote_close = function (state /*, token*/) {
state.result += '</blockquote>\n';
};


rules.bullet_list_open = function (state, token) {
rules.bullet_list_open = function (state /*, token*/) {
state.result += '<ul>\n';
};
rules.bullet_list_close = function (state, token) {
rules.bullet_list_close = function (state /*, token*/) {
state.result += '</ul>\n';
};

Expand Down Expand Up @@ -59,23 +59,23 @@ rules.heading_close = function (state, token) {
};


rules.hr = function (state, token) {
rules.hr = function (state/*, token*/) {
state.result += '<hr>\n';
};


rules.list_item_open = function (state, token) {
rules.list_item_open = function (state /*, token*/) {
state.result += '<li>';
};
rules.list_item_close = function (state, token) {
rules.list_item_close = function (state /*, token*/) {
state.result += '</li>\n';
};


rules.paragraph_open = function (state, token) {
rules.paragraph_open = function (state /*, token*/) {
state.result += '<p>';
};
rules.paragraph_close = function (state, token) {
rules.paragraph_close = function (state /*, token*/) {
state.result += '</p>\n';
};

Expand All @@ -98,7 +98,7 @@ Renderer.prototype.render = function (state) {

// TODO: temporary check
if (!rule) {
throw Error('Renderer error: unknown token ' + tokens[i].type);
throw new Error('Renderer error: unknown token ' + tokens[i].type);
}

rule(state, tokens[i]);
Expand Down
4 changes: 2 additions & 2 deletions lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function State(src, lexerBlock, lexerInline, renderer, tokens, options) {
indent = 0;
indent_found = false;

for(start = pos = indent = 0, len = s.length; pos < len; pos++) {
for (start = pos = indent = 0, len = s.length; pos < len; pos++) {
ch = s.charCodeAt(pos);

// TODO: check other spaces and tabs too or keep existing regexp replace ??
Expand Down Expand Up @@ -101,4 +101,4 @@ State.prototype.clone = function clone(src) {
);
};

module.exports = State;
module.exports = State;
Loading

0 comments on commit a8f9ea5

Please sign in to comment.