Skip to content

Commit

Permalink
[eslint] enable and manually fix no-useless-escape
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 19, 2019
1 parent 3d19e2f commit 13be022
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 13 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

"prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],

"no-useless-escape": 1,
"function-paren-newline": 0,
"no-plusplus": 1,
"no-param-reassign": 1,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = {

if (argType === 'Identifier' && /^[A-Z_]/.test(argument.name)) {
reportIfForbidden(argument.name, argument);
} else if (argType === 'Literal' && /^[a-z][^\.]*$/.test(argument.value)) {
} else if (argType === 'Literal' && /^[a-z][^.]*$/.test(argument.value)) {
reportIfForbidden(argument.value, argument);
} else if (argType === 'MemberExpression') {
reportIfForbidden(sourceCode.getText(argument), argument);
Expand Down
2 changes: 1 addition & 1 deletion lib/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {String} message - Message to log.
*/
function error(message) {
if (!/\=-(f|-format)=/.test(process.argv.join('='))) {
if (!/=-(f|-format)=/.test(process.argv.join('='))) {
// eslint-disable-next-line no-console
console.error(message);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const elementType = require('jsx-ast-utils/elementType');

const COMPAT_TAG_REGEX = /^[a-z]|\-/;
const COMPAT_TAG_REGEX = /^[a-z]|-/;

/**
* Checks if a node represents a DOM element.
Expand Down
2 changes: 1 addition & 1 deletion lib/util/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {String} message - Message to log.
*/
function log(message) {
if (!/\=-(f|-format)=/.test(process.argv.join('='))) {
if (!/=-(f|-format)=/.test(process.argv.join('='))) {
// eslint-disable-next-line no-console
console.log(message);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function isSuperTypeParameterPropsDeclaration(node) {
* @param {string} string the identifier to strip
*/
function stripQuotes(string) {
return string.replace(/^\'|\'$/g, '');
return string.replace(/^'|'$/g, '');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/util/usedPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
* @param {string} string the identifier to strip
*/
function stripQuotes(string) {
return string.replace(/^\'|\'$/g, '');
return string.replace(/^'|'$/g, '');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/no-unescaped-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ruleTester.run('no-unescaped-entities', rule, {
});
`,
parser: parsers.BABEL_ESLINT,
errors: [{message: 'HTML entity, \`&\` , must be escaped.'}],
errors: [{message: 'HTML entity, `&` , must be escaped.'}],
options: [{
forbid: ['&']
}]
Expand All @@ -211,7 +211,7 @@ ruleTester.run('no-unescaped-entities', rule, {
}
});
`,
errors: [{message: 'HTML entity, \`&\` , must be escaped.'}],
errors: [{message: 'HTML entity, `&` , must be escaped.'}],
options: [{
forbid: ['&']
}]
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2642,10 +2642,10 @@ ruleTester.run('no-unused-prop-types', rule, {
}, {
code: `
type Props = {
\'completed?\': boolean,
'completed?': boolean,
};
const Hello = (props: Props): React.Element => {
return <div>{props[\'completed?\']}</div>;
return <div>{props['completed?']}</div>;
}
`,
parser: parsers.BABEL_ESLINT
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ eslintTester.run('no-unused-state', rule, {
this.state = { foo: 0, bar: 1 };
}
render() {
const bar = \'bar\';
const bar = 'bar';
return <SomeComponent bar={this.state[bar]} />;
}
}`,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ eslintTester.run('no-unused-state', rule, {
const foo = ((this: any).state: any).foo;
const {bar, ...others} = (this.state: any);
let baz;
baz = (others: any)[\'baz\'];
baz = (others: any)['baz'];
return <SomeComponent foo={foo} bar={bar} baz={baz} />;
}
}`,
Expand Down

0 comments on commit 13be022

Please sign in to comment.