Browse Source

replaced jshint with eslint for better style check

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
a8f9ea5b57
  1. 3
      .eslintignore
  2. 47
      .eslintrc
  3. 82
      .jshintrc
  4. 2
      Makefile
  5. 9
      benchmark/benchmark.js
  6. 5
      benchmark/profile.js
  7. 8
      bin/remarkable.js
  8. 2
      lib/helpers.js
  9. 2
      lib/lexer_block/blockquote.js
  10. 2
      lib/lexer_block/code.js
  11. 9
      lib/lexer_block/fences.js
  12. 2
      lib/lexer_block/heading.js
  13. 2
      lib/lexer_block/lheading.js
  14. 4
      lib/lexer_block/list.js
  15. 20
      lib/renderer.js
  16. 4
      lib/state.js
  17. 4
      package.json
  18. 2
      test/remarkable.js
  19. 2
      test/stmd.js
  20. 4
      test/utils.js

3
.jshintignore → .eslintignore

@ -1,5 +1,4 @@
.git/
benchmark/implementations/
node_modules/
demo/
dist/
node_modules/

47
.eslintrc

@ -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
.jshintrc

@ -1,82 +0,0 @@
{
// Enforcing Options /////////////////////////////////////////////////////////
"bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.).
// false - specific for js-yaml
"camelcase" : false, // Require variable names to be camelCase style or UPPER_CASE
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"indent" : 2, // This option enforces specific tab width for your code
"latedef" : false, // Prohibit hariable use before definition.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`.
"quotmark" : false, // Enforces the consistency of quotation marks used throughout your code.
"regexp" : false, // Prohibit `.` and `[^...]` in regular expressions.
"undef" : true, // Require all non-global variables be declared before they are used.
"unused" : false, // This option warns when you define and never use your variables.
"strict" : true, // Require `use strict` pragma in every file.
"trailing" : true, // Prohibit trailing whitespaces.
"maxparams" : 6, // Enforce max number of formal parameters allowed per function
"maxdepth" : 5, // Enforce max depth of nested blocks
"maxstatements" : false, // Enforce max amount of statements per function
"maxcomplexity" : false, // Enforce cyclomatic complexity level
// Relaxing Options //////////////////////////////////////////////////////////
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // Tolerate use of `== null`.
//"es5" : true, // Allow ECMAScript 5 syntax.
"esnext" : false, // Allow ES.next specific features such as const and let
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"funcscope" : false, // Tolerate declaring variables inside of control structures while accessing them later
"globalstrict" : true, // Allow global "use strict" (also enables 'strict').
"iterator" : false, // Allow usage of __iterator__ property.
"lastsemic" : false, // Tolerate semicolon omited for the last statement.
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"laxcomma" : true, // This option suppresses warnings about comma-first coding style
"loopfunc" : false, // Allow functions to be defined within loops.
"multistr" : false, // Tolerate multi-line strings.
"onecase" : false, // Tolerate swithes with only one case.
"proto" : false, // Allow usage of __proto__ property.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : true, // Tolerate script-targeted URLs.
"smarttabs" : false, // Allow mixed tabs and spaces when the latter are used for alignmnent only.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"supernew" : true, // Tolerate `new function () { ... };` and `new Object;`.
// Environments //////////////////////////////////////////////////////////////
"browser" : false, // Defines globals exposed by modern browsers
"couch" : false, // Defines globals exposed by CouchDB
"devel" : false, // Allow developments statements e.g. `console.log();`.
"dojo" : false, // Defines globals exposed by the Dojo Toolkit
"jquery" : false, // Defines globals exposed by the jQuery
"mootools" : false, // Defines globals exposed by the MooTools
"node" : true, // Defines globals exposed when running under Node.JS
"nonstandard" : false, // Defines non-standard but widely adopted globals such as escape and unescape
"prototypejs" : false, // Defines globals exposed by the Prototype
"rhino" : false, // Defines globals exposed when running under Rhino
"worker" : false, // Defines globals exposed when running Web Worker
"wsh" : false, // Defines globals exposed when running under WSH
// Legacy ////////////////////////////////////////////////////////////////////
"nomen" : false, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"passfail" : false, // Stop on first error.
"white" : false, // Check against strict whitespace and indentation rules.
// Other /////////////////////////////////////////////////////////////////////
"maxerr" : 100 // Maximum error before stopping.
}

2
Makefile

@ -19,7 +19,7 @@ demo: lint browserify
lint:
jshint . --show-non-errors
eslint ./
test: lint

9
benchmark/benchmark.js

@ -1,4 +1,5 @@
#!/usr/bin/env node
/*eslint no-console:0*/
'use strict';
@ -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({
@ -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;
}

5
benchmark/profile.js

@ -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
bin/remarkable.js

@ -1,5 +1,5 @@
#!/usr/bin/env node
/*eslint no-console:0*/
'use strict';
@ -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'
});
@ -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);
}

2
lib/helpers.js

@ -64,4 +64,4 @@ exports.isEmpty = isEmpty;
exports.skipEmptyLines = skipEmptyLines;
exports.skipSpaces = skipSpaces;
exports.skipChars = skipChars;
exports.getLines = getLines;
exports.getLines = getLines;

2
lib/lexer_block/blockquote.js

@ -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];

2
lib/lexer_block/code.js

@ -39,4 +39,4 @@ module.exports = function code(state, startLine, endLine, silent) {
state.line = nextLine;
return true;
};
};

9
lib/lexer_block/fences.js

@ -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];
@ -35,7 +35,7 @@ module.exports =function fences(state, startLine, endLine, silent) {
// search end of block
nextLine = startLine;
do {
for (;;) {
nextLine++;
if (nextLine >= endLine) {
@ -63,8 +63,7 @@ module.exports =function fences(state, startLine, endLine, silent) {
// found!
break;
} while (true);
}
if (silent) { return true; }
@ -76,4 +75,4 @@ module.exports =function fences(state, startLine, endLine, silent) {
state.line = skipEmptyLines(state, nextLine + 1);
return true;
};
};

2
lib/lexer_block/heading.js

@ -69,4 +69,4 @@ module.exports = function heading(state, startLine, endLine, silent) {
state.line = skipEmptyLines(state, ++startLine);
return true;
};
};

2
lib/lexer_block/lheading.js

@ -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 });

4
lib/lexer_block/list.js

@ -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++);
@ -79,4 +78,3 @@ module.exports = function list(state, startLine, endLine, silent) {
}
return false;
};

20
lib/renderer.js

@ -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';
};
@ -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';
};
@ -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]);

4
lib/state.js

@ -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 ??
@ -101,4 +101,4 @@ State.prototype.clone = function clone(src) {
);
};
module.exports = State;
module.exports = State;

4
package.json

@ -23,10 +23,10 @@
"ansi": "^0.3.0",
"benchmark": "^1.0.0",
"browserify": "*",
"eslint": "^0.8.0",
"eslint-plugin-nodeca": "^1.0.0",
"jade": "1.6.0",
"jshint": "*",
"mocha": "*",
"uglifyjs": "*"
}
}

2
test/remarkable.js

@ -13,4 +13,4 @@ describe('Default', function () {
var md = new Remarked();
utils.addTests(path.join(__dirname, 'fixtures/remarkable'), md);
});
});

2
test/stmd.js

@ -27,4 +27,4 @@ describe('stmd original with error', function () {
var md = new Remarked();
utils.addTests(path.join(__dirname, 'fixtures/stmd_conflicting'), md, true);
});
});

4
test/utils.js

@ -32,7 +32,7 @@ function addTests(dir, md, skip) {
ext = path.extname(name),
base = path.basename(name, ext);
if (['.md', '.markdown'].indexOf(ext) !== -1) {
if ([ '.md', '.markdown' ].indexOf(ext) !== -1) {
src = fixtures[name];
right = fixtures[base + '.html'];
@ -53,4 +53,4 @@ function addTests(dir, md, skip) {
}
module.exports.addTests = addTests;
module.exports.addTests = addTests;

Loading…
Cancel
Save