Repository: jamesramsay/hercule
Pull request #203 (2016-03-17 10:01:41)

New: eslint-plugin-lodash


Patch:
diff --git a/.eslintrc.json b/.eslintrc.json
index e7e8259..e68b2b4 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -2,9 +2,13 @@
   "env": {
     "node": true
   },
-  "extends": "airbnb/base",
+  "extends": [
+    "airbnb/base",
+    "plugin:lodash/recommended"
+  ],
   "plugins": [
-    "ava"
+    "ava",
+    "lodash"
   ],
   "rules": {
     "id-length": [2, {"min": 2, "max": 25, "properties": "never", "exceptions": ["_"]}],
diff --git a/package.json b/package.json
index b3bf259..39cf860 100644
--- a/package.json
+++ b/package.json
@@ -70,6 +70,7 @@
     "eslint": "^2.2.0",
     "eslint-config-airbnb": "^6.0.1",
     "eslint-plugin-ava": "^1.2.0",
+    "eslint-plugin-lodash": "^1.4.1",
     "istanbul": "^0.4.1",
     "nock": "^7.0.2",
     "nyc": "^6.0.0",
diff --git a/src/config.js b/src/config.js
index 757df02..9912f36 100644
--- a/src/config.js
+++ b/src/config.js
@@ -17,7 +17,7 @@ export function defaultToken(match, options, whitespace) {
   return {
     content: match[MATCH_GROUP],
     link: { href: _.isFunction(options.linkMatch) ? options.linkMatch(match) : match[LINK_GROUP] },
-    indent: _([whitespace, match[WHITESPACE_GROUP]]).filter(_.isString).value().join(''),
+    indent: _.filter([whitespace, match[WHITESPACE_GROUP]], _.isString).join(''),
     relativePath: options.relativePath,
     references: options.references || [],
     parents: options.parents || [],
diff --git a/src/hercule.js b/src/hercule.js
index b3343e2..0e002bf 100644
--- a/src/hercule.js
+++ b/src/hercule.js
@@ -62,7 +62,7 @@ export function transcludeFileSync(input, options) {
   const syncOptions = { cwd: __dirname, timeout: SYNC_TIMEOUT };
   const syncArgs = [input, '--reporter', 'json-err'];
 
-  _.each(options, (optionValue, optionName) => {
+  _.forEach(options, (optionValue, optionName) => {
     syncArgs.push(`--${optionName}`, `${optionValue}`);
   });
 
@@ -80,7 +80,7 @@ export function transcludeStringSync(input, options) {
   const syncOptions = { input, cwd: __dirname, timeout: SYNC_TIMEOUT };
   const syncArgs = ['--reporter', 'json-err'];
 
-  _.each(options, (optionValue, optionName) => {
+  _.forEach(options, (optionValue, optionName) => {
     syncArgs.push(`--${optionName}`, `${optionValue}`);
   });
 
diff --git a/src/inflate-stream.js b/src/inflate-stream.js
index e1e06aa..a888f31 100644
--- a/src/inflate-stream.js
+++ b/src/inflate-stream.js
@@ -70,7 +70,7 @@ export default function InflateStream(opt, linkPaths) {
       return cb();
     }
 
-    if (_(parents).includes(link.href)) {
+    if (_.includes(parents, link.href)) {
       this.push(chunk);
       this.emit('error', {
         msg: 'Circular dependency detected',
@@ -79,7 +79,7 @@ export default function InflateStream(opt, linkPaths) {
       return cb();
     }
 
-    if (_(SUPPORTED_LINK_TYPES).includes(link.hrefType) === false) {
+    if (_.includes(SUPPORTED_LINK_TYPES, link.hrefType) === false) {
       this.push(chunk);
       return cb();
     }
diff --git a/src/resolve-stream.js b/src/resolve-stream.js
index 1e7f7b6..d998d15 100644
--- a/src/resolve-stream.js
+++ b/src/resolve-stream.js
@@ -76,7 +76,7 @@ export default function ResolveStream(grammar, opt, linkPaths = []) {
       return { placeholder, hrefType, href: relativeHref };
     });
 
-    references = _.uniq([...references, ...parentRefs], true);
+    references = _.uniq([...references, ...parentRefs]);
     link = resolve(link, parentRefs, relativePath);
 
     linkPaths.push(link.href);


Test patch:
diff --git a/test/units/transcludeFile.js b/test/units/transcludeFile.js
index 1441612..ec81518 100644
--- a/test/units/transcludeFile.js
+++ b/test/units/transcludeFile.js
@@ -1,6 +1,5 @@
 import test from 'ava';
 import path from 'path';
-import _ from 'lodash';
 
 import { transcludeFile } from '../../lib/hercule';
 
@@ -35,17 +34,17 @@ test.cb('should return error if file doesn\'t exist', (t) => {
   });
 });
 
-// test.cb('should return error if circular dependency found', (t) => {
-//   const input = path.join(__dirname, '../fixtures/circular-references/index.md');
-//   const options = { relativePath: path.join(__dirname, '../fixtures/circular-references') };
-//   transcludeFile(input, options, (err, output) => {
-//     t.ok(err);
-//     t.same(err.msg, 'Circular dependency detected');
-//     t.regex(err.path, /fixtures\/circular-references\/fox.md/);
-//     t.notOk(output);
-//     t.end();
-//   });
-// });
+test.cb('should return error if circular dependency found', (t) => {
+  const input = path.join(__dirname, '../fixtures/circular-references/index.md');
+  const options = { relativePath: path.join(__dirname, '../fixtures/circular-references') };
+  const expected = 'The quick brown :[fox](fox.md) jumps over the lazy dog.\n';
+  transcludeFile(input, options, (err, output) => {
+    t.same(err.msg, 'Circular dependency detected');
+    t.regex(err.path, /fixtures\/circular-references\/fox.md/);
+    t.same(output, expected);
+    t.end();
+  });
+});
 
 test.cb('should provide pathList if variable provided', (t) => {
   const input = path.join(__dirname, '../fixtures/local-link/index.md');
@@ -68,7 +67,7 @@ test.cb('should support tokenizer options', (t) => {
   const options = {
     relativePath: path.join(__dirname, '../fixtures/_aglio'),
     linkRegExp: new RegExp(/(^[\t ]*)?(\:\[.*?\]\((.*?)\))|()( *<!-- include\((.*)\) -->)/gm),
-    linkMatch: (match) => _.get(match, '[3]') || _.get(match, '[6]'),
+    linkMatch: (match) => match[3] || match[6],
   };
 
   transcludeFile(input, options, (err, output) => {
diff --git a/test/units/transcludeString.js b/test/units/transcludeString.js
index 6700ba7..3098883 100644
--- a/test/units/transcludeString.js
+++ b/test/units/transcludeString.js
@@ -1,5 +1,4 @@
 import test from 'ava';
-import _ from 'lodash';
 
 import { transcludeString } from '../../lib/hercule';
 
@@ -41,7 +40,7 @@ test.cb('should support tokenizer options', (t) => {
   const expected = 'The quick brown fox jumps over the lazy dog.';
   const options = {
     linkRegExp: new RegExp(/(^[\t ]*)?(\:\[.*?\]\((.*?)\))|()( *<!-- include\((.*)\) -->)/gm),
-    linkMatch: (match) => _.get(match, '[3]') || _.get(match, '[6]'),
+    linkMatch: (match) => match[3] || match[6],
   };
 
   transcludeString(input, options, (err, output) => {