-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rule - react-style-no-numeric-string-value): add rule to prevent…
… unitless string values see react(v15) issue facebook/react#1357
- Loading branch information
Mayank Agarwal
committed
Aug 23, 2016
1 parent
f88e0d1
commit 3e6c02d
Showing
3 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/rules/__tests__/react-style-no-numeric-string-value-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
import rule, { errorMessage } from '../react-style-no-numeric-string-value'; | ||
import dedent from 'dedent-js'; | ||
import RuleTester from '../../utils/RuleTester'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: 'babel-eslint', | ||
}); | ||
|
||
const error = (others = {}) => ({ | ||
message: 'no-numeric-string-value', | ||
...others, | ||
}); | ||
|
||
ruleTester.run('react-style-no-numeric-string-value', rule, { | ||
valid: [ | ||
{ | ||
// dont report errors for non css property | ||
code: ` | ||
const someObject = { | ||
test: '10', | ||
}; | ||
` | ||
}, | ||
|
||
{ | ||
// dont report errors for non css property | ||
code: ` | ||
const someObject = { | ||
width: '10px', | ||
}; | ||
` | ||
}, | ||
|
||
{ | ||
// numbers are allowed | ||
code: ` | ||
const someObject = { | ||
width: 10, | ||
}; | ||
` | ||
}, | ||
|
||
|
||
{ | ||
// dont report errors for css property which supports unitless number | ||
code: ` | ||
const someObject = { | ||
lineHeight: '10', | ||
}; | ||
` | ||
} | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: ` | ||
const style = { | ||
width: '10', | ||
}; | ||
`, | ||
output: ` | ||
const style = { | ||
width: '10px', | ||
}; | ||
`, | ||
errors: [{ | ||
message: errorMessage({ property: 'width', rawValue: "'10'", fixedRawValue: "'10px'" }), | ||
line: 3, | ||
column: 18, | ||
}], | ||
}, | ||
|
||
{ | ||
// zero replace with numeric zero | ||
code: ` | ||
const style = { | ||
width: '0', | ||
}; | ||
`, | ||
output: ` | ||
const style = { | ||
width: 0, | ||
}; | ||
`, | ||
errors: [{ | ||
message: errorMessage({ property: 'width', rawValue: "'0'", fixedRawValue: '0' }), | ||
line: 3, | ||
column: 18, | ||
}], | ||
}, | ||
|
||
{ | ||
code: ` | ||
const jsx = ( | ||
<StyleProvider style={{ width: '100%', height: '250' }} /> | ||
); | ||
`, | ||
output: ` | ||
const jsx = ( | ||
<StyleProvider style={{ width: '100%', height: '250px' }} /> | ||
); | ||
`, | ||
errors: [{ | ||
message: errorMessage({ property: 'height', rawValue: "'250'", fixedRawValue: "'250px'" }), | ||
line: 3, | ||
column: 58, | ||
}], | ||
} | ||
], | ||
}); |
Oops, something went wrong.