Skip to content

Commit

Permalink
[eslint] use template literals instead of multiline strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 29, 2017
1 parent d4aa408 commit 87026a1
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-multi-str": 0,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new": 2,
"no-new-func": 2,
Expand Down
274 changes: 146 additions & 128 deletions tests/lib/rules/jsx-uses-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,170 +32,188 @@ eslint.defineRule('jsx-uses-vars', require('../../../lib/rules/jsx-uses-vars'));
ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
valid: [
{
code: '\
/*eslint jsx-uses-vars:1*/\
function foo() {\
var App;\
var bar = React.render(<App/>);\
return bar;\
};\
foo()',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var App;\
React.render(<App/>);',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var App;\
React.render(<App/>);',
code: `
/* eslint jsx-uses-vars: 1 */
function foo() {
var App;
var bar = React.render(<App/>);
return bar;
};
foo()
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var App;
React.render(<App/>);
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var App;
React.render(<App/>);
`,
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var a=1;\
React.render(<img src={a} />);',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var App;\
function f() {\
return <App />;\
}\
f();',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var App;\
<App.Hello />',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var App;\
<App:Hello />',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
class HelloMessage {}\
<HelloMessage />',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
class HelloMessage {\
render() {\
var HelloMessage = <div>Hello</div>;\
return HelloMessage;\
}\
}\
<HelloMessage />',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
function foo() {\
var App = { Foo: { Bar: {}}};\
var bar = React.render(<App.Foo.Bar/>);\
return bar;\
};\
foo()',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
function foo() {\
var App = { Foo: { Bar: { Baz: {}}}};\
var bar = React.render(<App.Foo.Bar.Baz/>);\
return bar;\
};\
foo()',
code: `
/* eslint jsx-uses-vars: 1 */
var a = 1;
React.render(<img src={a} />);
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var App;
function f() {
return <App />;
}
f();
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var App;
<App.Hello />
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var App;
<App:Hello />
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
class HelloMessage {}
<HelloMessage />
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
class HelloMessage {
render() {
var HelloMessage = <div>Hello</div>;
return HelloMessage;
}
}
<HelloMessage />
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
function foo() {
var App = { Foo: { Bar: {} } };
var bar = React.render(<App.Foo.Bar/>);
return bar;
};
foo()
`,
parserOptions: parserOptions
}, {
code: `
/* eslint jsx-uses-vars: 1 */
function foo() {
var App = { Foo: { Bar: { Baz: {} } } };
var bar = React.render(<App.Foo.Bar.Baz/>);
return bar;
};
foo()
`,
parserOptions: parserOptions
}
],
invalid: [
{
code: '/*eslint jsx-uses-vars:1*/ var App;',
code: '/* eslint jsx-uses-vars: 1 */ var App;',
errors: [{message: '\'App\' is defined but never used.'}],
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var App;\
var unused;\
React.render(<App unused=""/>);',
code: `
/* eslint jsx-uses-vars: 1 */
var App;
var unused;
React.render(<App unused=""/>);
`,
errors: [{message: '\'unused\' is defined but never used.'}],
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var App;\
var Hello;\
React.render(<App:Hello/>);',
code: `
/* eslint jsx-uses-vars: 1 */
var App;
var Hello;
React.render(<App:Hello/>);
`,
errors: [{message: '\'Hello\' is defined but never used.'}],
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
var Button;\
var Input;\
React.render(<Button.Input unused=""/>);',
code: `
/* eslint jsx-uses-vars: 1 */
var Button;
var Input;
React.render(<Button.Input unused=""/>);
`,
errors: [{message: '\'Input\' is defined but never used.'}],
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
class unused {}',
code: `
/* eslint jsx-uses-vars: 1 */
class unused {}
`,
errors: [{message: '\'unused\' is defined but never used.'}],
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
class HelloMessage {\
render() {\
var HelloMessage = <div>Hello</div>;\
return HelloMessage;\
}\
}',
code: `
/* eslint jsx-uses-vars: 1 */
class HelloMessage {
render() {
var HelloMessage = <div>Hello</div>;
return HelloMessage;
}
}
`,
errors: [{
message: '\'HelloMessage\' is defined but never used.',
line: 1
line: 3
}],
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
class HelloMessage {\
render() {\
var HelloMessage = <div>Hello</div>;\
return HelloMessage;\
}\
}',
code: `
/* eslint jsx-uses-vars: 1 */
class HelloMessage {
render() {
var HelloMessage = <div>Hello</div>;
return HelloMessage;
}
}
`,
errors: [{
message: '\'HelloMessage\' is defined but never used.',
line: 1
line: 3
}],
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
code: '\
/*eslint jsx-uses-vars:1*/\
import {Hello} from \'Hello\';\
function Greetings() {\
const Hello = require(\'Hello\').default;\
return <Hello />;\
}\
Greetings();',
code: `
/* eslint jsx-uses-vars: 1 */
import {Hello} from 'Hello';
function Greetings() {
const Hello = require('Hello').default;
return <Hello />;
}
Greetings();
`,
errors: [{
message: '\'Hello\' is defined but never used.',
line: 1
line: 3
}],
parser: 'babel-eslint',
parserOptions: parserOptions
Expand Down
Loading

0 comments on commit 87026a1

Please sign in to comment.