Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 21, 2018
1 parent 71a0308 commit ce62e7a
Show file tree
Hide file tree
Showing 111 changed files with 5,305 additions and 4,553 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
@@ -0,0 +1,3 @@
coverage/
remark.js
remark.min.js
18 changes: 13 additions & 5 deletions package.json
Expand Up @@ -18,6 +18,7 @@
"mdast-util-compact": "^1.0.0",
"mdast-zone": "^3.0.1",
"nyc": "^13.0.0",
"prettier": "^1.14.3",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.5.1",
"tinyify": "^2.4.3",
Expand All @@ -30,25 +31,32 @@
},
"scripts": {
"postinstall": "lerna bootstrap --no-ci",
"build-md": "packages/remark-cli/cli.js . -qfo",
"format": "packages/remark-cli/cli.js . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify packages/remark -s remark > remark.js",
"build-mangle": "browserify packages/remark -s remark -p tinyify > remark.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test/api",
"test-api-extensive": "TEST_EXTENDED=true node test/api",
"test-cli": "node test/cli.js",
"test-coverage": "nyc --reporter lcov tape test",
"test": "npm run build && npm run lint && npm run test-coverage"
"test": "npm run format && npm run build && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,
"rules": {
"import/no-unassigned-import": "off",
Expand Down
14 changes: 7 additions & 7 deletions packages/remark-cli/cli.js
@@ -1,11 +1,11 @@
#!/usr/bin/env node
'use strict';
'use strict'

var start = require('unified-args');
var extensions = require('markdown-extensions');
var processor = require('remark');
var proc = require('remark/package.json');
var cli = require('./package.json');
var start = require('unified-args')
var extensions = require('markdown-extensions')
var processor = require('remark')
var proc = require('remark/package.json')
var cli = require('./package.json')

start({
processor: processor,
Expand All @@ -21,4 +21,4 @@ start({
rcName: '.' + proc.name + 'rc',
ignoreName: '.' + proc.name + 'ignore',
extensions: extensions
});
})
21 changes: 12 additions & 9 deletions packages/remark-parse/index.js
@@ -1,14 +1,17 @@
'use strict';
'use strict'

var unherit = require('unherit');
var xtend = require('xtend');
var Parser = require('./lib/parser.js');
var unherit = require('unherit')
var xtend = require('xtend')
var Parser = require('./lib/parser.js')

module.exports = parse;
parse.Parser = Parser;
module.exports = parse
parse.Parser = Parser

function parse(options) {
var Local = unherit(Parser);
Local.prototype.options = xtend(Local.prototype.options, this.data('settings'), options);
this.Parser = Local;
var settings = this.data('settings')
var Local = unherit(Parser)

Local.prototype.options = xtend(Local.prototype.options, settings, options)

this.Parser = Local
}
64 changes: 29 additions & 35 deletions packages/remark-parse/lib/decode.js
@@ -1,48 +1,34 @@
'use strict';
'use strict'

var xtend = require('xtend');
var entities = require('parse-entities');
var xtend = require('xtend')
var entities = require('parse-entities')

module.exports = factory;
module.exports = factory

/* Factory to create an entity decoder. */
// Factory to create an entity decoder.
function factory(ctx) {
decoder.raw = decodeRaw;
decoder.raw = decodeRaw

return decoder;
return decoder

/* Normalize `position` to add an `indent`. */
// Normalize `position` to add an `indent`.
function normalize(position) {
var offsets = ctx.offset;
var line = position.line;
var result = [];
var offsets = ctx.offset
var line = position.line
var result = []

while (++line) {
if (!(line in offsets)) {
break;
break
}

result.push((offsets[line] || 0) + 1);
result.push((offsets[line] || 0) + 1)
}

return {
start: position,
indent: result
};
return {start: position, indent: result}
}

/* Handle a warning.
* See https://github.com/wooorm/parse-entities
* for the warnings. */
function handleWarning(reason, position, code) {
if (code === 3) {
return;
}

ctx.file.message(reason, position);
}

/* Decode `value` (at `position`) into text-nodes. */
// Decode `value` (at `position`) into text-nodes.
function decoder(value, position, handler) {
entities(value, {
position: normalize(position),
Expand All @@ -51,14 +37,22 @@ function factory(ctx) {
reference: handler,
textContext: ctx,
referenceContext: ctx
});
})
}

/* Decode `value` (at `position`) into a string. */
// Decode `value` (at `position`) into a string.
function decodeRaw(value, position, options) {
return entities(value, xtend(options, {
position: normalize(position),
warning: handleWarning
}));
return entities(
value,
xtend(options, {position: normalize(position), warning: handleWarning})
)
}

// Handle a warning.
// See <https://github.com/wooorm/parse-entities> for the warnings.
function handleWarning(reason, position, code) {
if (code !== 3) {
ctx.file.message(reason, position)
}
}
}
4 changes: 2 additions & 2 deletions packages/remark-parse/lib/defaults.js
@@ -1,4 +1,4 @@
'use strict';
'use strict'

module.exports = {
position: true,
Expand All @@ -7,4 +7,4 @@ module.exports = {
footnotes: false,
pedantic: false,
blocks: require('./block-elements.json')
};
}
12 changes: 6 additions & 6 deletions packages/remark-parse/lib/locate/break.js
@@ -1,17 +1,17 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
var index = value.indexOf('\n', fromIndex);
var index = value.indexOf('\n', fromIndex)

while (index > fromIndex) {
if (value.charAt(index - 1) !== ' ') {
break;
break
}

index--;
index--
}

return index;
return index
}
6 changes: 3 additions & 3 deletions packages/remark-parse/lib/locate/code-inline.js
@@ -1,7 +1,7 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
return value.indexOf('`', fromIndex);
return value.indexOf('`', fromIndex)
}
6 changes: 3 additions & 3 deletions packages/remark-parse/lib/locate/delete.js
@@ -1,7 +1,7 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
return value.indexOf('~~', fromIndex);
return value.indexOf('~~', fromIndex)
}
14 changes: 7 additions & 7 deletions packages/remark-parse/lib/locate/emphasis.js
@@ -1,18 +1,18 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
var asterisk = value.indexOf('*', fromIndex);
var underscore = value.indexOf('_', fromIndex);
var asterisk = value.indexOf('*', fromIndex)
var underscore = value.indexOf('_', fromIndex)

if (underscore === -1) {
return asterisk;
return asterisk
}

if (asterisk === -1) {
return underscore;
return underscore
}

return underscore < asterisk ? underscore : asterisk;
return underscore < asterisk ? underscore : asterisk
}
6 changes: 3 additions & 3 deletions packages/remark-parse/lib/locate/escape.js
@@ -1,7 +1,7 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
return value.indexOf('\\', fromIndex);
return value.indexOf('\\', fromIndex)
}
16 changes: 8 additions & 8 deletions packages/remark-parse/lib/locate/link.js
@@ -1,16 +1,16 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
var link = value.indexOf('[', fromIndex);
var image = value.indexOf('![', fromIndex);
var link = value.indexOf('[', fromIndex)
var image = value.indexOf('![', fromIndex)

if (image === -1) {
return link;
return link
}

/* Link can never be `-1` if an image is found, so we don’t need
* to check for that :) */
return link < image ? link : image;
// Link can never be `-1` if an image is found, so we don’t need to check
// for that :)
return link < image ? link : image
}
14 changes: 7 additions & 7 deletions packages/remark-parse/lib/locate/strong.js
@@ -1,18 +1,18 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
var asterisk = value.indexOf('**', fromIndex);
var underscore = value.indexOf('__', fromIndex);
var asterisk = value.indexOf('**', fromIndex)
var underscore = value.indexOf('__', fromIndex)

if (underscore === -1) {
return asterisk;
return asterisk
}

if (asterisk === -1) {
return underscore;
return underscore
}

return underscore < asterisk ? underscore : asterisk;
return underscore < asterisk ? underscore : asterisk
}
6 changes: 3 additions & 3 deletions packages/remark-parse/lib/locate/tag.js
@@ -1,7 +1,7 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

function locate(value, fromIndex) {
return value.indexOf('<', fromIndex);
return value.indexOf('<', fromIndex)
}
22 changes: 11 additions & 11 deletions packages/remark-parse/lib/locate/url.js
@@ -1,26 +1,26 @@
'use strict';
'use strict'

module.exports = locate;
module.exports = locate

var PROTOCOLS = ['https://', 'http://', 'mailto:'];
var protocols = ['https://', 'http://', 'mailto:']

function locate(value, fromIndex) {
var length = PROTOCOLS.length;
var index = -1;
var min = -1;
var position;
var length = protocols.length
var index = -1
var min = -1
var position

if (!this.options.gfm) {
return -1;
return -1
}

while (++index < length) {
position = value.indexOf(PROTOCOLS[index], fromIndex);
position = value.indexOf(protocols[index], fromIndex)

if (position !== -1 && (position < min || min === -1)) {
min = position;
min = position
}
}

return min;
return min
}

0 comments on commit ce62e7a

Please sign in to comment.