tslint-react
Advanced tools
Comparing version 3.1.0 to 3.2.0
{ | ||
"name": "tslint-react", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Lint rules related to React & JSX for TSLint", | ||
@@ -12,13 +12,12 @@ "main": "tslint-react.json", | ||
"scripts": { | ||
"build": "npm-run-all -p compile lint", | ||
"build": "tsc -p ./", | ||
"clean": "rm -rf build/", | ||
"compile": "tsc -p ./", | ||
"copy": "cp -f package.json README.md tslint-react.json build/", | ||
"lint": "tslint 'src/**/*.ts'", | ||
"lint": "tslint --project tsconfig.json --format stylish", | ||
"preversion": "npm-run-all clean verify copy", | ||
"test-rules": "scripts/testRules.sh", | ||
"verify": "npm-run-all build test-rules" | ||
"verify": "npm-run-all build lint test-rules" | ||
}, | ||
"dependencies": { | ||
"tsutils": "^1.7.0" | ||
"tsutils": "^2.8.0" | ||
}, | ||
@@ -34,9 +33,9 @@ "peerDependencies": { | ||
"colors": "^1.1.2", | ||
"glob": "^7.1.1", | ||
"glob": "^7.1.2", | ||
"npm-run-all": "^4.0.2", | ||
"path": "^0.12.7", | ||
"tslint": "^5.1.0", | ||
"tsutils": "^1.7.0", | ||
"typescript": "^2.3" | ||
"tslint": "^5.5.0", | ||
"tslint-language-service": "^0.9.6", | ||
"typescript": "~2.4.2" | ||
} | ||
} |
@@ -61,2 +61,10 @@ [![NPM version](https://badge.fury.io/js/tslint-react.svg)](https://www.npmjs.com/package/tslint-react) | ||
- _Includes automatic code fix_ | ||
- `jsx-equals-spacing` (since v3.2.0) | ||
- Requires _or_ bans spaces before and after the `=` token in JSX element attributes. | ||
- Rule options: `["always", "never"]` | ||
- _Includes automatic code fix_ | ||
- `jsx-key` (since v3.2.0) | ||
- Warns for missing `key` props in JSX element array literals and inside return statements of `Array.prototype.map` callbacks. | ||
- N.B. This rule only does a simple check for `.map(...)` syntax and does not inspect computed types of expressions. As such, it may produce false positives if you use APIs that look similar to `.map()`. | ||
- Rule options: _none_ | ||
- `jsx-no-bind` (since v2.6.0) | ||
@@ -63,0 +71,0 @@ - Forbids function binding in JSX attributes. This has the same intent as `jsx-no-lambda` in helping you avoid excessive re-rendres. |
@@ -40,20 +40,20 @@ "use strict"; | ||
}; | ||
// tslint:disable object-literal-sort-keys | ||
Rule.metadata = { | ||
ruleName: "jsx-alignment", | ||
description: "Enforces consistent and readable vertical alignment of JSX tags and attributes", | ||
optionsDescription: "Not configurable.", | ||
options: null, | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
// tslint:enable object-literal-sort-keys | ||
Rule.ATTR_LINE_FAILURE = "JSX attributes must be on a line below the opening tag"; | ||
Rule.ATTR_INDENT_FAILURE = "JSX attributes must be indented further than the opening tag statement"; | ||
Rule.ATTR_ALIGN_FAILURE = "JSX attributes must be on their own line and vertically aligned"; | ||
Rule.TAG_CLOSE_FAILURE = "Tag closing must be on its own line and aligned with opening of tag"; | ||
Rule.CLOSING_TAG_FAILURE = "Closing tag must be on its own line and aligned with opening tag"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
// tslint:disable object-literal-sort-keys | ||
Rule.metadata = { | ||
ruleName: "jsx-alignment", | ||
description: "Enforces consistent and readable vertical alignment of JSX tags and attributes", | ||
optionsDescription: "Not configurable.", | ||
options: null, | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
// tslint:enable object-literal-sort-keys | ||
Rule.ATTR_LINE_FAILURE = "JSX attributes must be on a line below the opening tag"; | ||
Rule.ATTR_INDENT_FAILURE = "JSX attributes must be indented further than the opening tag statement"; | ||
Rule.ATTR_ALIGN_FAILURE = "JSX attributes must be on their own line and vertically aligned"; | ||
Rule.TAG_CLOSE_FAILURE = "Tag closing must be on its own line and aligned with opening of tag"; | ||
Rule.CLOSING_TAG_FAILURE = "Closing tag must be on its own line and aligned with opening tag"; | ||
exports.Rule = Rule; | ||
@@ -81,4 +81,4 @@ var LEADING_WHITESPACE_REGEX = /[ \t]/; | ||
elementClose, closingTag) { | ||
attributes = attributes == null || Array.isArray(attributes) ? attributes : attributes.properties; | ||
if (attributes == null || attributes.length === 0) { | ||
attributes = Array.isArray(attributes) ? attributes : attributes.properties; | ||
if (attributes.length === 0) { | ||
return; | ||
@@ -116,3 +116,3 @@ } | ||
// ensure closing tag is on its own line and aligned with the opening tag | ||
if (closingTag != null) { | ||
if (closingTag !== undefined) { | ||
var closingTagLocation = getLineAndCharacter(closingTag); | ||
@@ -119,0 +119,0 @@ if (closingTagLocation.line <= elementClose.line || closingTagLocation.character !== initialIndent) { |
@@ -38,3 +38,3 @@ "use strict"; | ||
Rule.prototype.apply = function (sourceFile) { | ||
var bannedProps = this.ruleArguments | ||
var bannedProps = this.ruleArguments.length > 0 | ||
? new Map(this.ruleArguments.map(function (prop) { | ||
@@ -46,26 +46,27 @@ return [prop[0], prop.length > 1 ? prop[1] : ""]; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-ban-props", | ||
description: "Bans the use of specific props.", | ||
optionsDescription: (_a = ["\n A list of `['propName', 'optional explanation here']` which bans the prop called 'propName'."], _a.raw = ["\n A list of \\`['propName', 'optional explanation here']\\` which bans the prop called 'propName'."], Lint.Utils.dedent(_a)), | ||
options: { | ||
type: "list", | ||
listType: { | ||
type: "string", | ||
items: { type: "string" }, | ||
minLength: 1, | ||
maxLength: 2, | ||
}, | ||
}, | ||
optionExamples: ["[true, [\"someProp], [\"anotherProp\", \"Optional explanation\"]]"], | ||
type: "functionality", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING_FACTORY = function (propName, explanation) { | ||
var explanationSuffix = explanation === undefined || explanation === "" ? "" : " " + explanation; | ||
return "Use of the prop '" + propName + "' is not allowed." + explanationSuffix; | ||
}; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-ban-props", | ||
description: "Bans the use of specific props.", | ||
optionsDescription: (_a = ["\n A list of `['propName', 'optional explanation here']` which bans the prop called 'propName'."], _a.raw = ["\n A list of \\`['propName', 'optional explanation here']\\` which bans the prop called 'propName'."], Lint.Utils.dedent(_a)), | ||
options: { | ||
type: "list", | ||
listType: { | ||
type: "string", | ||
items: { type: "string" }, | ||
minLength: 1, | ||
maxLength: 2, | ||
}, | ||
}, | ||
optionExamples: ["[true, [\"someProp], [\"anotherProp\", \"Optional explanation\"]]"], | ||
type: "functionality", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING_FACTORY = function (propName, explanation) { | ||
return "Use of the prop '" + propName + "' is not allowed." + (explanation ? " " + explanation : ""); | ||
}; | ||
exports.Rule = Rule; | ||
@@ -72,0 +73,0 @@ function walk(ctx) { |
@@ -43,28 +43,28 @@ "use strict"; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-boolean-value", | ||
description: "Enforce boolean attribute notation in jsx.", | ||
optionsDescription: (_a = ["\n One of the following two options must be provided:\n * `\"", "\"` requires JSX boolean values to always be set.\n * `\"", "\"` prevents JSX boolean values to be explicity set as `true`"], _a.raw = ["\n One of the following two options must be provided:\n * \\`\"", "\"\\` requires JSX boolean values to always be set.\n * \\`\"", "\"\\` prevents JSX boolean values to be explicity set as \\`true\\`"], Lint.Utils.dedent(_a, OPTION_ALWAYS, OPTION_NEVER)), | ||
options: { | ||
type: "array", | ||
items: [{ | ||
enum: [OPTION_ALWAYS, OPTION_NEVER], | ||
type: "string", | ||
}], | ||
minLength: 1, | ||
maxLength: 1, | ||
}, | ||
optionExamples: [ | ||
"[true, \"" + OPTION_ALWAYS + "\"]", | ||
"[true, \"" + OPTION_NEVER + "\"]", | ||
], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.NEVER_MESSAGE = "Value must be omitted for boolean attributes"; | ||
Rule.ALWAYS_MESSAGE = "Value must be set for boolean attributes"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-boolean-value", | ||
description: "Enforce boolean attribute notation in jsx.", | ||
optionsDescription: (_a = ["\n One of the following two options must be provided:\n * `\"", "\"` requires JSX boolean values to always be set.\n * `\"", "\"` prevents JSX boolean values to be explicity set as `true`"], _a.raw = ["\n One of the following two options must be provided:\n * \\`\"", "\"\\` requires JSX boolean values to always be set.\n * \\`\"", "\"\\` prevents JSX boolean values to be explicity set as \\`true\\`"], Lint.Utils.dedent(_a, OPTION_ALWAYS, OPTION_NEVER)), | ||
options: { | ||
type: "array", | ||
items: [{ | ||
enum: [OPTION_ALWAYS, OPTION_NEVER], | ||
type: "string", | ||
}], | ||
minLength: 1, | ||
maxLength: 1, | ||
}, | ||
optionExamples: [ | ||
"[true, \"" + OPTION_ALWAYS + "\"]", | ||
"[true, \"" + OPTION_NEVER + "\"]", | ||
], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.NEVER_MESSAGE = "Value must be omitted for boolean attributes"; | ||
Rule.ALWAYS_MESSAGE = "Value must be set for boolean attributes"; | ||
exports.Rule = Rule; | ||
@@ -71,0 +71,0 @@ function walk(ctx) { |
@@ -32,2 +32,3 @@ "use strict"; | ||
var ts = require("typescript"); | ||
var utils_1 = require("../utils"); | ||
var OPTION_ALWAYS = "always"; | ||
@@ -40,3 +41,2 @@ var OPTION_NEVER = "never"; | ||
}; | ||
var NEWLINE_REGEX = /\n/; | ||
var Rule = (function (_super) { | ||
@@ -51,27 +51,27 @@ __extends(Rule, _super); | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-curly-spacing", | ||
description: "Checks JSX curly braces spacing", | ||
optionsDescription: (_a = ["\n One of the following two options must be provided:\n\n * `\"", "\"` requires JSX attributes to have spaces between curly braces\n * `\"", "\"` requires JSX attributes to NOT have spaces between curly braces"], _a.raw = ["\n One of the following two options must be provided:\n\n * \\`\"", "\"\\` requires JSX attributes to have spaces between curly braces\n * \\`\"", "\"\\` requires JSX attributes to NOT have spaces between curly braces"], Lint.Utils.dedent(_a, OPTION_ALWAYS, OPTION_NEVER)), | ||
options: { | ||
type: "array", | ||
items: [SPACING_OBJECT], | ||
minLength: 1, | ||
maxLength: 1, | ||
}, | ||
optionExamples: [ | ||
"[true, \"" + OPTION_ALWAYS + "\"]", | ||
"[true, \"" + OPTION_NEVER + "\"]", | ||
], | ||
type: "style", | ||
typescriptOnly: true, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_NO_ENDING_SPACE = function (token) { return "A space is required before " + token; }; | ||
Rule.FAILURE_NO_BEGINNING_SPACE = function (token) { return "A space is required after " + token; }; | ||
Rule.FAILURE_FORBIDDEN_SPACES_BEGINNING = function (token) { return "There should be no space after " + token; }; | ||
Rule.FAILURE_FORBIDDEN_SPACES_END = function (token) { return "There should be no space before " + token; }; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-curly-spacing", | ||
description: "Checks JSX curly braces spacing", | ||
optionsDescription: (_a = ["\n One of the following two options must be provided:\n\n * `\"", "\"` requires JSX attributes to have spaces between curly braces\n * `\"", "\"` requires JSX attributes to NOT have spaces between curly braces"], _a.raw = ["\n One of the following two options must be provided:\n\n * \\`\"", "\"\\` requires JSX attributes to have spaces between curly braces\n * \\`\"", "\"\\` requires JSX attributes to NOT have spaces between curly braces"], Lint.Utils.dedent(_a, OPTION_ALWAYS, OPTION_NEVER)), | ||
options: { | ||
type: "array", | ||
items: [SPACING_OBJECT], | ||
minLength: 1, | ||
maxLength: 1, | ||
}, | ||
optionExamples: [ | ||
"[true, \"" + OPTION_ALWAYS + "\"]", | ||
"[true, \"" + OPTION_NEVER + "\"]", | ||
], | ||
type: "style", | ||
typescriptOnly: true, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_NO_ENDING_SPACE = function (token) { return "A space is required before " + token; }; | ||
Rule.FAILURE_NO_BEGINNING_SPACE = function (token) { return "A space is required after " + token; }; | ||
Rule.FAILURE_FORBIDDEN_SPACES_BEGINNING = function (token) { return "There should be no space after " + token; }; | ||
Rule.FAILURE_FORBIDDEN_SPACES_END = function (token) { return "There should be no space before " + token; }; | ||
exports.Rule = Rule; | ||
@@ -93,3 +93,3 @@ function walk(ctx) { | ||
if (ctx.options === OPTION_ALWAYS) { | ||
var deleteFix = maybeGetDeleteFixForSpaceBetweenTokens(firstToken, secondToken); | ||
var deleteFix = utils_1.getDeleteFixForSpaceBetweenTokens(firstToken, secondToken); | ||
if (deleteFix === undefined) { | ||
@@ -100,3 +100,3 @@ var fix = Lint.Replacement.appendText(secondToken.getFullStart(), " "); | ||
} | ||
deleteFix = maybeGetDeleteFixForSpaceBetweenTokens(secondToLastToken, lastToken); | ||
deleteFix = utils_1.getDeleteFixForSpaceBetweenTokens(secondToLastToken, lastToken); | ||
if (deleteFix === undefined) { | ||
@@ -111,4 +111,4 @@ var fix = Lint.Replacement.appendText(lastToken.getStart(), " "); | ||
var lastAndSecondToLastCombinedText = getTokensCombinedText(secondToLastToken, lastToken); | ||
if (!isExpressionMultiline(firstAndSecondTokensCombinedText)) { | ||
var fix = maybeGetDeleteFixForSpaceBetweenTokens(firstToken, secondToken); | ||
if (!utils_1.isMultilineText(firstAndSecondTokensCombinedText)) { | ||
var fix = utils_1.getDeleteFixForSpaceBetweenTokens(firstToken, secondToken); | ||
if (fix !== undefined) { | ||
@@ -119,4 +119,4 @@ var failureString = Rule.FAILURE_FORBIDDEN_SPACES_BEGINNING(firstToken.getText()); | ||
} | ||
if (!isExpressionMultiline(lastAndSecondToLastCombinedText)) { | ||
var fix = maybeGetDeleteFixForSpaceBetweenTokens(secondToLastToken, lastToken); | ||
if (!utils_1.isMultilineText(lastAndSecondToLastCombinedText)) { | ||
var fix = utils_1.getDeleteFixForSpaceBetweenTokens(secondToLastToken, lastToken); | ||
if (fix !== undefined) { | ||
@@ -136,28 +136,3 @@ var failureString = Rule.FAILURE_FORBIDDEN_SPACES_END(lastToken.getText()); | ||
} | ||
function maybeGetDeleteFixForSpaceBetweenTokens(firstNode, secondNode) { | ||
if (firstNode.parent !== secondNode.parent) { | ||
throw Error("Expected identical parents for both nodes"); | ||
} | ||
var parent = firstNode.parent; | ||
var parentStart = parent.getStart(); | ||
var secondNodeStart = secondNode.getFullStart(); | ||
var firstNodeEnd = firstNode.getStart() + firstNode.getWidth(); | ||
var secondNodeRelativeStart = secondNodeStart - parentStart; | ||
var firstNodeRelativeEnd = firstNodeEnd - parentStart; | ||
var parentText = parent.getText(); | ||
var trailingComments = ts.getTrailingCommentRanges(parentText, firstNodeRelativeEnd) || []; | ||
var leadingComments = ts.getLeadingCommentRanges(parentText, secondNodeRelativeStart) || []; | ||
var comments = trailingComments.concat(leadingComments); | ||
if (secondNode.getStart() - firstNode.getStart() - firstNode.getWidth() > getTotalCharCount(comments)) { | ||
var replacements = comments.map(function (comment) { return parentText.slice(comment.pos, comment.end); }).join(""); | ||
return new Lint.Replacement(secondNodeStart, secondNode.getStart() - secondNodeStart, replacements); | ||
} | ||
else { | ||
return undefined; | ||
} | ||
} | ||
} | ||
function isExpressionMultiline(text) { | ||
return NEWLINE_REGEX.test(text); | ||
} | ||
function getTokensCombinedText(firstToken, nextToken) { | ||
@@ -172,7 +147,2 @@ var parentNodeText = nextToken.parent.getText(); | ||
} | ||
function getTotalCharCount(comments) { | ||
return comments | ||
.map(function (comment) { return comment.end - comment.pos; }) | ||
.reduce(function (l, r) { return l + r; }, 0); | ||
} | ||
var _a; |
@@ -44,17 +44,17 @@ "use strict"; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-bind", | ||
description: (_a = ["Forbids function binding in JSX attributes. This has the same intent as jsx-no-lambda in helping you avoid excessive re-renders."], _a.raw = ["Forbids function binding in JSX attributes. This has the same intent \\\n as jsx-no-lambda in helping you avoid excessive re-renders."], Lint.Utils.dedent(_a)), | ||
descriptionDetails: (_b = ["Note that this currently only does a simple syntactic check, not a semantic one (it doesn't use the type checker). So it may have some rare false positives if you define your own .bind function and supply this as a parameter."], _b.raw = ["Note that this currently only does a simple syntactic check, \\\n not a semantic one (it doesn't use the type checker). So it may \\\n have some rare false positives if you define your own .bind function \\\n and supply this as a parameter."], Lint.Utils.dedent(_b)), | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "functionality", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Binds are forbidden in JSX attributes due to their rendering performance impact"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-bind", | ||
description: (_a = ["Forbids function binding in JSX attributes. This has the same intent as jsx-no-lambda in helping you avoid excessive re-renders."], _a.raw = ["Forbids function binding in JSX attributes. This has the same intent \\\n as jsx-no-lambda in helping you avoid excessive re-renders."], Lint.Utils.dedent(_a)), | ||
descriptionDetails: (_b = ["Note that this currently only does a simple syntactic check, not a semantic one (it doesn't use the type checker). So it may have some rare false positives if you define your own .bind function and supply this as a parameter."], _b.raw = ["Note that this currently only does a simple syntactic check, \\\n not a semantic one (it doesn't use the type checker). So it may \\\n have some rare false positives if you define your own .bind function \\\n and supply this as a parameter."], Lint.Utils.dedent(_b)), | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "functionality", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Binds are forbidden in JSX attributes due to their rendering performance impact"; | ||
exports.Rule = Rule; | ||
@@ -61,0 +61,0 @@ function walk(ctx) { |
@@ -40,17 +40,17 @@ "use strict"; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-lambda", | ||
description: "Checks for fresh lambda literals used in JSX attributes", | ||
descriptionDetails: (_a = ["Creating new anonymous functions (with either the function syntax or ES2015 arrow syntax) inside the render call stack works against pure component rendering. When doing an equality check between two lambdas, React will always consider them unequal values and force the component to re-render more often than necessary."], _a.raw = ["Creating new anonymous functions (with either the function syntax or \\\n ES2015 arrow syntax) inside the render call stack works against pure component \\\n rendering. When doing an equality check between two lambdas, React will always \\\n consider them unequal values and force the component to re-render more often than necessary."], Lint.Utils.dedent(_a)), | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "functionality", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Lambdas are forbidden in JSX attributes due to their rendering performance impact"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-lambda", | ||
description: "Checks for fresh lambda literals used in JSX attributes", | ||
descriptionDetails: (_a = ["Creating new anonymous functions (with either the function syntax or ES2015 arrow syntax) inside the render call stack works against pure component rendering. When doing an equality check between two lambdas, React will always consider them unequal values and force the component to re-render more often than necessary."], _a.raw = ["Creating new anonymous functions (with either the function syntax or \\\n ES2015 arrow syntax) inside the render call stack works against pure component \\\n rendering. When doing an equality check between two lambdas, React will always \\\n consider them unequal values and force the component to re-render more often than necessary."], Lint.Utils.dedent(_a)), | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "functionality", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Lambdas are forbidden in JSX attributes due to their rendering performance impact"; | ||
exports.Rule = Rule; | ||
@@ -57,0 +57,0 @@ function walk(ctx) { |
@@ -40,17 +40,17 @@ "use strict"; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-multiline-js", | ||
description: "Checks for multiline JS expressions inside JSX expressions", | ||
descriptionDetails: "This helps reduce mental overhead when parsing JSX syntax", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Multiline JS expressions inside JSX are forbidden"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-multiline-js", | ||
description: "Checks for multiline JS expressions inside JSX expressions", | ||
descriptionDetails: "This helps reduce mental overhead when parsing JSX syntax", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Multiline JS expressions inside JSX are forbidden"; | ||
exports.Rule = Rule; | ||
@@ -57,0 +57,0 @@ function walk(ctx) { |
@@ -40,17 +40,17 @@ "use strict"; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-string-ref", | ||
description: "Checks for string literal refs", | ||
descriptionDetails: "This syntax is deprecated and will be removed in a future version of React", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Pass a callback to ref prop instead of a string literal"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-no-string-ref", | ||
description: "Checks for string literal refs", | ||
descriptionDetails: "This syntax is deprecated and will be removed in a future version of React", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "Pass a callback to ref prop instead of a string literal"; | ||
exports.Rule = Rule; | ||
@@ -61,4 +61,4 @@ function walk(ctx) { | ||
var name = node.name, initializer = node.initializer; | ||
var isRefAttribute = name != null && name.text === "ref"; | ||
if (isRefAttribute && initializer != null) { | ||
var isRefAttribute = name.text === "ref"; | ||
if (isRefAttribute && initializer !== undefined) { | ||
var hasStringInitializer = initializer.kind === ts.SyntaxKind.StringLiteral; | ||
@@ -65,0 +65,0 @@ var hasStringExpressionInitializer = tsutils_1.isJsxExpression(initializer) |
@@ -40,16 +40,16 @@ "use strict"; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-self-close", | ||
description: "Checks that JSX elements with no children are self-closing", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "JSX elements with no children must be self-closing"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-self-close", | ||
description: "Checks that JSX elements with no children are self-closing", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_STRING = "JSX elements with no children must be self-closing"; | ||
exports.Rule = Rule; | ||
@@ -56,0 +56,0 @@ function walk(ctx) { |
@@ -40,9 +40,9 @@ "use strict"; | ||
}; | ||
Rule.TRANSLATABLE_ATTRIBUTES = new Set(["placeholder", "title", "alt"]); | ||
Rule.FAILURE_STRING = "String literals are disallowed as JSX. Use a translation function"; | ||
Rule.FAILURE_STRING_FACTORY = function (text) { | ||
return "String literal is not allowed for value of " + text + ". Use a translation function"; | ||
}; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
Rule.TRANSLATABLE_ATTRIBUTES = new Set(["placeholder", "title", "alt"]); | ||
Rule.FAILURE_STRING = "String literals are disallowed as JSX. Use a translation function"; | ||
Rule.FAILURE_STRING_FACTORY = function (text) { | ||
return "String literal is not allowed for value of " + text + ". Use a translation function"; | ||
}; | ||
exports.Rule = Rule; | ||
@@ -66,3 +66,3 @@ function walk(ctx) { | ||
else if (tsutils_1.isJsxAttribute(node)) { | ||
if (Rule.TRANSLATABLE_ATTRIBUTES.has(node.name.text) && node.initializer) { | ||
if (Rule.TRANSLATABLE_ATTRIBUTES.has(node.name.text) && node.initializer !== undefined) { | ||
if (tsutils_1.isStringLiteral(node.initializer) | ||
@@ -69,0 +69,0 @@ || (tsutils_1.isJsxExpression(node.initializer) && tsutils_1.isStringLiteral(node.initializer.expression))) { |
@@ -40,18 +40,18 @@ "use strict"; | ||
}; | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-wrap-multiline", | ||
description: "Checks that multiline JSX elements are wrapped in parens", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_NOT_WRAPPED = "Multiline JSX elements must be wrapped in parentheses"; | ||
Rule.FAILURE_MISSING_NEW_LINE_AFTER_OPEN = "New line required after open parenthesis when wrapping multiline JSX elements"; | ||
Rule.FAILURE_MISSING_NEW_LINE_BEFORE_CLOSE = "New line requred before close parenthesis when wrapping multiline JSX elements"; | ||
return Rule; | ||
}(Lint.Rules.AbstractRule)); | ||
/* tslint:disable:object-literal-sort-keys */ | ||
Rule.metadata = { | ||
ruleName: "jsx-wrap-multiline", | ||
description: "Checks that multiline JSX elements are wrapped in parens", | ||
options: null, | ||
optionsDescription: "", | ||
optionExamples: ["true"], | ||
type: "style", | ||
typescriptOnly: false, | ||
}; | ||
/* tslint:enable:object-literal-sort-keys */ | ||
Rule.FAILURE_NOT_WRAPPED = "Multiline JSX elements must be wrapped in parentheses"; | ||
Rule.FAILURE_MISSING_NEW_LINE_AFTER_OPEN = "New line required after open parenthesis when wrapping multiline JSX elements"; | ||
Rule.FAILURE_MISSING_NEW_LINE_BEFORE_CLOSE = "New line requred before close parenthesis when wrapping multiline JSX elements"; | ||
exports.Rule = Rule; | ||
@@ -95,3 +95,3 @@ var JsxWrapMultilineWalker = (function (_super) { | ||
var nextToken = siblings[index + 1]; | ||
if (prevTokenKind === ts.SyntaxKind.OpenParenToken && node.getFullText().match(/^[\r\n]+/)) { | ||
if (prevTokenKind === ts.SyntaxKind.OpenParenToken && node.getFullText().match(/^[\r\n]+/) !== null) { | ||
return; | ||
@@ -98,0 +98,0 @@ } |
@@ -7,2 +7,4 @@ { | ||
"jsx-curly-spacing": [true, "never"], | ||
"jsx-equals-spacing": [true, "never"], | ||
"jsx-key": true, | ||
"jsx-no-bind": true, | ||
@@ -9,0 +11,0 @@ "jsx-no-lambda": true, |
80500
33
1679
131
- Removedtsutils@1.9.1(transitive)
Updatedtsutils@^2.8.0