eslint-plugin-flowtype & upgrade to eslint@4 (#849)

* Add eslint-plugin-flowtype. Fix #844

Using the recommended settings for plugin.
This involved adding some spaces to some existing union types.

* Upgrade to eslint@4, fix spotted bugs

Switched to indent-legacy to allow e.g. comments to have extra indents.
This commit is contained in:
Erik Demaine
2017-09-07 11:06:26 +09:00
committed by Kevin Barabash
parent cb7f166a7e
commit 588f5a1ee6
8 changed files with 23 additions and 14 deletions

View File

@@ -1,5 +1,12 @@
{ {
"parser": "babel-eslint", "parser": "babel-eslint",
"plugins": [
"flowtype"
],
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"rules": { "rules": {
"arrow-spacing": 2, "arrow-spacing": 2,
"brace-style": [2, "1tbs", { "allowSingleLine": true }], "brace-style": [2, "1tbs", { "allowSingleLine": true }],
@@ -12,7 +19,8 @@
"eol-last": 2, "eol-last": 2,
"eqeqeq": [2, "allow-null"], "eqeqeq": [2, "allow-null"],
"guard-for-in": 2, "guard-for-in": 2,
"indent": [2, 4, {"SwitchCase": 1}], "indent": "off",
"indent-legacy": [2, 4, {"SwitchCase": 1}],
"keyword-spacing": 2, "keyword-spacing": 2,
"linebreak-style": [2, "unix"], "linebreak-style": [2, "unix"],
"max-len": [2, 84, 4, { "ignoreUrls": true, "ignorePattern": "\\brequire\\([\"']|eslint-disable" }], "max-len": [2, 84, 4, { "ignoreUrls": true, "ignorePattern": "\\brequire\\([\"']|eslint-disable" }],
@@ -79,6 +87,5 @@
"node": true, "node": true,
"browser": true "browser": true
}, },
"extends": "eslint:recommended",
"root": true "root": true
} }

View File

@@ -26,7 +26,8 @@
"babelify": "^7.3.0", "babelify": "^7.3.0",
"browserify": "^13.3.0", "browserify": "^13.3.0",
"clean-css": "^3.4.23", "clean-css": "^3.4.23",
"eslint": "^3.13.0", "eslint": "^4.6.1",
"eslint-plugin-flowtype": "^2.35.1",
"express": "^4.14.0", "express": "^4.14.0",
"flow-bin": "^0.54.0", "flow-bin": "^0.54.0",
"glob": "^7.1.1", "glob": "^7.1.1",

View File

@@ -11,11 +11,12 @@ import {Token} from "./Token";
* about where in the source string the problem occurred. * about where in the source string the problem occurred.
*/ */
class ParseError { class ParseError {
position: number|void; // Error position based on passed-in Token or ParseNode. position: number | void;
// Error position based on passed-in Token or ParseNode.
constructor( constructor(
message: string, // The error message message: string, // The error message
token?: Token|ParseNode, // An object providing position information token?: Token | ParseNode, // An object providing position information
) { ) {
let error = "KaTeX parse error: " + message; let error = "KaTeX parse error: " + message;
let start; let start;

View File

@@ -16,9 +16,9 @@ export default class ParseNode {
// TODO: We should combine these to ({lexer, start, end}|void) as they // TODO: We should combine these to ({lexer, start, end}|void) as they
// should all exist together or not exist at all. That way, only a single // should all exist together or not exist at all. That way, only a single
// void check needs to be done to see if we have metadata. // void check needs to be done to see if we have metadata.
lexer: LexerInterface|void; lexer: LexerInterface | void;
start: number|void; start: number | void;
end: number|void; end: number | void;
constructor( constructor(
type: string, // type of node, like e.g. "ordgroup" type: string, // type of node, like e.g. "ordgroup"

View File

@@ -847,7 +847,7 @@ class Parser {
} }
return new ParseFuncOrArgument( return new ParseFuncOrArgument(
new ParseNode("ordgroup", expression, this.mode, new ParseNode("ordgroup", expression, this.mode,
firstToken, lastToken), firstToken, lastToken),
false); false);
} else { } else {
// Otherwise, just return a nucleus, or nothing for an optional group // Otherwise, just return a nucleus, or nothing for an optional group

View File

@@ -216,7 +216,7 @@ defineMacro("\\dotsi", "\\!\\cdots");
// amsmath doesn't actually define \dotsx, but \dots followed by a macro // amsmath doesn't actually define \dotsx, but \dots followed by a macro
// starting with \DOTSX implies \dotso, and then \extra@ detects this case // starting with \DOTSX implies \dotso, and then \extra@ detects this case
// and forces the added `\,`. // and forces the added `\,`.
defineMacro("\\dotsx", "\\ldots\,"); defineMacro("\\dotsx", "\\ldots\\,");
// \let\DOTSI\relax // \let\DOTSI\relax
// \let\DOTSB\relax // \let\DOTSB\relax

View File

@@ -286,7 +286,7 @@ describe("environments.js:", function() {
}); });
it("rejects incorrectly scoped \\end", function() { it("rejects incorrectly scoped \\end", function() {
expect("{\\begin{matrix}1}\\end{matrix}").toFailWithParseError( expect("{\\begin{matrix}1}\\end{matrix}").toFailWithParseError(
"Expected & or \\\\\ or \\end at position 17:" + "Expected & or \\\\ or \\end at position 17:" +
" …\\begin{matrix}1}̲\\end{matrix}"); " …\\begin{matrix}1}̲\\end{matrix}");
}); });
}); });

View File

@@ -2384,8 +2384,8 @@ describe("A macro expander", function() {
it("should expand the \\overset macro as expected", function() { it("should expand the \\overset macro as expected", function() {
expect("\\overset?=").toParseLike("\\mathop{=}\\limits^{?}"); expect("\\overset?=").toParseLike("\\mathop{=}\\limits^{?}");
expect("\\overset{x=y}{\sqrt{ab}}") expect("\\overset{x=y}{\\sqrt{ab}}")
.toParseLike("\\mathop{\sqrt{ab}}\\limits^{x=y}"); .toParseLike("\\mathop{\\sqrt{ab}}\\limits^{x=y}");
expect("\\overset {?} =").toParseLike("\\mathop{=}\\limits^{?}"); expect("\\overset {?} =").toParseLike("\\mathop{=}\\limits^{?}");
}); });