aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-06-28 21:51:50 +0100
committerMichael Williamson <mike@zwobble.org>2016-06-28 21:51:50 +0100
commit4b13398d9f4fc303d22fc24aac519113941b032c (patch)
tree7422aa51b30de16ff9a90fb8863f1503ef755642
parentd046c4297a04b6eecadf01093382b72bb1b71032 (diff)
Add stylistic eslint rules
-rw-r--r--lib/docx/body-reader.js9
-rw-r--r--lib/docx/docx-reader.js2
-rw-r--r--lib/style-reader.js2
-rw-r--r--lib/writers/markdown-writer.js4
-rw-r--r--lib/xml/nodes.js4
-rw-r--r--lib/xml/reader.js4
-rw-r--r--package.json61
-rw-r--r--tests/docx/files.tests.js4
-rw-r--r--tests/main.tests.js4
-rw-r--r--tests/mammoth.tests.js2
10 files changed, 80 insertions, 16 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index 71ad29d..c338893 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -232,7 +232,7 @@ function BodyReader(options) {
var properties = element.firstOrEmpty("w:tcPr");
var gridSpan = properties.firstOrEmpty("w:gridSpan").attributes["w:val"];
- var colSpan = gridSpan ? parseInt(gridSpan) : 1;
+ var colSpan = gridSpan ? parseInt(gridSpan, 10) : 1;
var cell = documents.TableCell(children, {colSpan: colSpan});
cell._vMerge = readVMerge(properties);
@@ -408,7 +408,6 @@ function joinZipPath(first, second) {
}
-
function emptyResultWithMessages(messages) {
return new ReadResult(null, null, messages);
}
@@ -466,7 +465,7 @@ function combineResults(results) {
var result = Result.combine(_.pluck(results, "_result"));
return new ReadResult(
_.flatten(_.pluck(result.value, "element")),
- _.filter(_.flatten(_.pluck(result.value, "extra")), function(x) { return x; }),
+ _.filter(_.flatten(_.pluck(result.value, "extra")), identity),
result.messages
);
}
@@ -474,3 +473,7 @@ function combineResults(results) {
function joinElements(first, second) {
return _.flatten([first, second]);
}
+
+function identity(value) {
+ return value;
+}
diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js
index 8ef4960..6ad63ab 100644
--- a/lib/docx/docx-reader.js
+++ b/lib/docx/docx-reader.js
@@ -57,7 +57,7 @@ function read(docxFile, input) {
bodyReader: bodyReader,
notes: notes
});
- return reader.convertXmlToDocument(xml);
+ return reader.convertXmlToDocument(xml);
});
});
});
diff --git a/lib/style-reader.js b/lib/style-reader.js
index 9969bbe..b5fb8ce 100644
--- a/lib/style-reader.js
+++ b/lib/style-reader.js
@@ -126,7 +126,7 @@ function documentMatcherRule() {
var underline = identifierToConstant("u", documentMatchers.underline);
var strikethrough = identifierToConstant("strike", documentMatchers.strikethrough);
- return lop.rules.firstOf("element type",
+ return lop.rules.firstOf("element type",
paragraphOrRun,
bold,
italic,
diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js
index 079d924..4284532 100644
--- a/lib/writers/markdown-writer.js
+++ b/lib/writers/markdown-writer.js
@@ -98,7 +98,9 @@ function markdownWriter() {
function open(tagName, attributes) {
attributes = attributes || {};
- var createElement = htmlToMarkdown[tagName] || function() { return {}; };
+ var createElement = htmlToMarkdown[tagName] || function() {
+ return {};
+ };
var element = createElement(attributes, list, listItem);
elementStack.push({end: element.end, list: list});
diff --git a/lib/xml/nodes.js b/lib/xml/nodes.js
index 9305918..76f5fd7 100644
--- a/lib/xml/nodes.js
+++ b/lib/xml/nodes.js
@@ -32,7 +32,7 @@ function Element(name, attributes, children) {
Element.prototype.first = function(name) {
return _.find(this.children, function(child) {
- return child.name == name;
+ return child.name === name;
});
};
@@ -42,7 +42,7 @@ Element.prototype.firstOrEmpty = function(name) {
Element.prototype.getElementsByTagName = function(name) {
var elements = _.filter(this.children, function(child) {
- return child.name == name;
+ return child.name === name;
});
return toElementList(elements);
};
diff --git a/lib/xml/reader.js b/lib/xml/reader.js
index 67b69be..844ee0c 100644
--- a/lib/xml/reader.js
+++ b/lib/xml/reader.js
@@ -78,8 +78,8 @@ function readString(xmlString, namespaceMap) {
function mapObject(input, valueFunc, keyFunc) {
return _.reduce(input, function(result, value, key) {
- var mappedKey = keyFunc.call(null, value, key, input);
- result[mappedKey] = valueFunc.call(null, value, key, input);
+ var mappedKey = keyFunc(value, key, input);
+ result[mappedKey] = valueFunc(value, key, input);
return result;
}, {});
}
diff --git a/package.json b/package.json
index 492757c..0e10a4d 100644
--- a/package.json
+++ b/package.json
@@ -53,9 +53,66 @@
"extends": "eslint:recommended",
"rules": {
- "indent": ["error", 4],
+ "curly": ["error", "all"],
+ "dot-location": ["error", "property"],
+ "no-alert": ["error"],
+ "no-caller": ["error"],
+ "no-eval": ["error"],
+ "no-extend-native": ["error"],
+ "no-extra-bind": ["error"],
+ "no-extra-label": ["error"],
+ "no-floating-decimal": ["error"],
+ "no-implicit-coercion": ["error", {"allow": ["!!"]}],
+ "no-implied-eval": ["error"],
+ "no-invalid-this": ["error"],
+ "no-labels": ["error"],
+ "no-lone-blocks": ["error"],
+ "no-native-reassign": ["error"],
+ "no-new": ["error"],
+ "no-new-func": ["error"],
+ "no-new-wrappers": ["error"],
+ "no-return-assign": ["error"],
+ "no-self-compare": ["error"],
+ "no-sequences": ["error"],
+ "no-throw-literal": ["error"],
+ "no-unused-expressions": ["error"],
+ "no-useless-call": ["error"],
+ "no-with": ["error"],
"no-unused-vars": ["error", {"args": "none"}],
- "object-curly-spacing": ["error", "never"]
+ "object-curly-spacing": ["error", "never"],
+ "radix": ["error", "always"],
+
+ "array-bracket-spacing": ["error", "never"],
+ "brace-style": ["error", "1tbs"],
+ "camelcase": ["error"],
+ "comma-spacing": ["error", {"before": false, "after": true}],
+ "comma-style": ["error", "last"],
+ "computed-property-spacing": ["error", "never"],
+ "eol-last": ["error"],
+ "indent": ["error", 4],
+ "key-spacing": [
+ "error",
+ {"beforeColon": false, "afterColon": true, "mode": "strict"}
+ ],
+ "keyword-spacing": ["error", {"before": true, "after": true}],
+ "new-parens": ["error"],
+ "no-array-constructor": ["error"],
+ "no-continue": ["error"],
+ "no-lonely-if": ["error"],
+ "no-multiple-empty-lines": ["error", {"max": 2, "maxEOF": 1}],
+ "no-new-object": ["error"],
+ "no-spaced-func": ["error"],
+ "no-trailing-spaces": ["error", {"skipBlankLines": true}],
+ "no-whitespace-before-property": ["error"],
+ "object-curly-spacing": ["error", "never"],
+ "one-var": ["error", "never"],
+ "semi": ["error", "always"],
+ "semi-spacing": ["error", {"before": false}],
+ "space-before-function-paren": ["error", "never"],
+ "space-in-parens": ["error", "never"],
+ "space-infix-ops": ["error"],
+ "space-unary-ops": ["error", {"words": true, "nonwords": false}],
+ "spaced-comment": ["error", "always"]
},
"globals": {
diff --git a/tests/docx/files.tests.js b/tests/docx/files.tests.js
index 10751d4..2a0919c 100644
--- a/tests/docx/files.tests.js
+++ b/tests/docx/files.tests.js
@@ -74,7 +74,9 @@ describe("uriToPath", function() {
});
test("when host is set but not localhost then path cannot be found", function() {
- assert.throws(function() { uriToPath("file://example/a/b/c"); }, /Could not convert URI to path: file:\/\/example\/a\/b\/c/);
+ assert.throws(function() {
+ uriToPath("file://example/a/b/c");
+ }, /Could not convert URI to path: file:\/\/example\/a\/b\/c/);
});
test("leading slash is not dropped on Windows file URIs when platform is not Windows", function() {
diff --git a/tests/main.tests.js b/tests/main.tests.js
index 5b54441..d603626 100644
--- a/tests/main.tests.js
+++ b/tests/main.tests.js
@@ -1,5 +1,5 @@
var assert = require("assert");
-var child_process = require("child_process");
+var child_process = require("child_process"); // eslint-disable-line camelcase
var path = require("path");
var fs = require("fs");
@@ -77,7 +77,7 @@ function runMammoth() {
var processArgs = ["node", "bin/mammoth"].concat(args);
// TODO: proper escaping of args
var command = processArgs.join(" ");
- child_process.exec(command, function(error, stdout, stderr) {
+ child_process.exec(command, function(error, stdout, stderr) { // eslint-disable-line camelcase
console.log(stderr); // eslint-disable-line no-console
assert.equal(error, null);
deferred.resolve({output: stdout, stderrOutput: stderr});
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index ad71539..1a82014 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -36,7 +36,7 @@ describe('mammoth', function() {
test('should read docx xml files with unicode byte order mark', function() {
var docxPath = path.join(__dirname, "test-data/utf8-bom.docx");
- return mammoth.convertToHtml({path: docxPath}).then(function (result) {
+ return mammoth.convertToHtml({path: docxPath}).then(function(result) {
assert.equal(result.value, "<p>This XML has a byte order mark.</p>");
assert.deepEqual(result.messages, []);
});