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

Commit

Permalink
Refactor code-style to use xo
Browse files Browse the repository at this point in the history
* Replace istanbul with nyc;
* Replace ESLint, jscs with xo;
* Update remark;
* Remove superfluous files;
* Remove unneeded Node Travis targets.
  • Loading branch information
wooorm committed Aug 24, 2016
1 parent 124a81c commit 14253dc
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 674 deletions.
8 changes: 1 addition & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ root = true

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

[*.{json,svg,remarkrc,eslintrc}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
remark-slug.js
Expand Down
41 changes: 0 additions & 41 deletions .jscs.json

This file was deleted.

14 changes: 0 additions & 14 deletions .remarkrc

This file was deleted.

8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
language: node_js
node_js:
- '0.11'
- '0.12'
- '4.0'
- '5.0'
- '6.0'
sudo: false
after_success:
- bash <(curl -s https://codecov.io/bash)
after_success: bash <(curl -s https://codecov.io/bash)
deploy:
- provider: npm
email: tituswormer@gmail.com
api_key:
secure: n6COjQjbWD4m01WvMa1tIKMrGSY940r5M2REOVaO4GBSE4vIb8VRn9JYLMZ5Dk41g6wJG30krdEftxTWhjpdB6N5v2xKnj5GkN97AFIZGOVDvhnADf07PeI/Rh0astNQ/d7R0Kle1ctBr4FU7+NapU0VqxsDmmk+yU+GkFLwGE/o9yu0rWdGoP9jlU54zppfDY3D/RB5y+WcxSiZ7zE38fxT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qTt7NRIhhUT4gCYQ0X0UyR1SdVf41UMOQCWR9zejYy0L75ccjsSyJgC0F9UFkZu/mbNKGFa2p+GnE/WoCW1MdyzWMbB7t7F94Oekiz4zlaj2zCHvehp6QkVE=
Expand Down
10 changes: 0 additions & 10 deletions example.js

This file was deleted.

71 changes: 0 additions & 71 deletions history.md

This file was deleted.

83 changes: 32 additions & 51 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,38 @@

'use strict';

/* eslint-env commonjs */

/*
* Dependencies.
*/

/* Dependencies. */
var toString = require('mdast-util-to-string');
var visit = require('unist-util-visit');
var slugs = require('github-slugger')();

/* Expose. */
module.exports = attacher;

/* Attacher. */
function attacher() {
return transformer;
}

/* Patch slugs on heading nodes. */
function transformer(ast) {
slugs.reset();

visit(ast, 'heading', function (node) {
var id = slugs.slug(toString(node));
var data = patch(node, 'data', {});

/* Non-html */
patch(data, 'id', id);
/* Legacy remark-html */
patch(data, 'htmlAttributes', {});
/* Current remark-html */
patch(data, 'hProperties', {});
patch(data.htmlAttributes, 'id', id);
patch(data.hProperties, 'id', id);
});
}

/**
* Patch `value` on `context` at `key`, if
* `context[key]` does not already exist.
Expand All @@ -27,50 +49,9 @@ var slugs = require('github-slugger')();
* @param {*} value - Value to patch.
*/
function patch(context, key, value) {
if (!context[key]) {
context[key] = value;
}

return context[key];
}

/**
* Patch slugs on heading nodes.
*
* Transformer is invoked for every file, so there’s no need
* to specify extra logic to get per-file slug pools.
*
* @param {Node} ast - Root node.
*/
function transformer(ast) {
slugs.reset();
if (!context[key]) {
context[key] = value;
}

visit(ast, 'heading', function (node) {
var id = slugs.slug(toString(node));
var data = patch(node, 'data', {});

/* Non-html */
patch(data, 'id', id);
/* Legacy remark-html */
patch(data, 'htmlAttributes', {});
/* Current remark-html */
patch(data, 'hProperties', {});
patch(data.htmlAttributes, 'id', id);
patch(data.hProperties, 'id', id);
});
return context[key];
}

/**
* Attacher.
*
* @return {Function} - Transformer.
*/
function attacher() {
return transformer;
}

/*
* Expose.
*/

module.exports = attacher;
34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,34 @@
],
"devDependencies": {
"browserify": "^13.0.0",
"eslint": "^3.0.0",
"esmangle": "^1.0.0",
"istanbul": "^0.4.0",
"jscs": "^3.0.0",
"jscs-jsdoc": "^2.0.0",
"nyc": "^8.1.0",
"remark": "^6.0.0",
"remark-cli": "^1.0.0",
"remark-comment-config": "^4.0.0",
"remark-github": "^5.0.0",
"remark-html": "^3.0.0",
"remark-lint": "^4.0.0",
"remark-usage": "^4.0.0",
"remark-validate-links": "^4.0.0",
"remark-cli": "^2.0.0",
"remark-preset-wooorm": "^1.0.0",
"tape": "^4.0.0",
"unist-util-remove-position": "^1.1.0"
"unist-builder": "^1.0.2",
"unist-util-remove-position": "^1.1.0",
"xo": "^0.16.0"
},
"scripts": {
"build-bundle": "browserify index.js --no-builtins -s remarkSlug > remark-slug.js",
"build-mangle": "esmangle remark-slug.js > remark-slug.min.js",
"build-md": "remark . --quiet --frail",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint-api": "eslint .",
"lint-style": "jscs --reporter inline .",
"lint": "npm run lint-api && npm run lint-style",
"lint": "xo",
"test-api": "node test.js",
"test-coverage": "istanbul cover test.js",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"xo": {
"space": true,
"ignores": [
"remark-slug.js"
]
},
"remarkConfig": {
"output": true,
"presets": "wooorm"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Yields:

Adds slugs to markdown headings.

Sets `data.id`, `data.hProperties.id` on heading nodes. The first can be
Sets `data.id`, `data.hProperties.id` on heading nodes. The first can be
used by any plugin as a unique identifier, the second tells **remark-html**
to use its value as an `id` attribute. **remark-slug** does not overwrite
these values when they already exist.
Expand Down
Loading

0 comments on commit 14253dc

Please sign in to comment.