Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add no-primitive-constructor-types rule
- Loading branch information
Aaron Harvey
committed
Nov 18, 2016
1 parent
8f355c2
commit 0d37f03
Showing
4 changed files
with
96 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
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,24 @@ | ||
import _ from 'lodash'; | ||
|
||
export default { | ||
create: (context) => { | ||
return { | ||
GenericTypeAnnotation: (node) => { | ||
const name = _.get(node, 'id.name'); | ||
|
||
if (RegExp(/(Boolean|Number|String)/).test(name)) { | ||
context.report({ | ||
data: { | ||
name | ||
}, | ||
loc: node.loc, | ||
message: 'Unexpected use of {{name}} constructor type.', | ||
node | ||
}); | ||
} | ||
} | ||
}; | ||
}, | ||
meta: {}, | ||
schema: {} | ||
}; |
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,69 @@ | ||
export default { | ||
invalid: [ | ||
{ | ||
code: 'type x = Number', | ||
errors: [{message: 'Unexpected use of Number constructor type.'}] | ||
}, | ||
{ | ||
code: 'type x = String', | ||
errors: [{message: 'Unexpected use of String constructor type.'}] | ||
}, | ||
{ | ||
code: 'type x = Boolean', | ||
errors: [{message: 'Unexpected use of Boolean constructor type.'}] | ||
}, | ||
{ | ||
code: 'type x = { a: Number }', | ||
errors: [{message: 'Unexpected use of Number constructor type.'}] | ||
}, | ||
{ | ||
code: 'type x = { a: String }', | ||
errors: [{message: 'Unexpected use of String constructor type.'}] | ||
}, | ||
{ | ||
code: 'type x = { a: Boolean }', | ||
errors: [{message: 'Unexpected use of Boolean constructor type.'}] | ||
}, | ||
{ | ||
code: '(x: Number) => {}', | ||
errors: [{message: 'Unexpected use of Number constructor type.'}] | ||
}, | ||
{ | ||
code: '(x: String) => {}', | ||
errors: [{message: 'Unexpected use of String constructor type.'}] | ||
}, | ||
{ | ||
code: '(x: Boolean) => {}', | ||
errors: [{message: 'Unexpected use of Boolean constructor type.'}] | ||
} | ||
], | ||
valid: [ | ||
{ | ||
code: 'type x = number' | ||
}, | ||
{ | ||
code: 'type x = string' | ||
}, | ||
{ | ||
code: 'type x = boolean' | ||
}, | ||
{ | ||
code: 'type x = { a: number }' | ||
}, | ||
{ | ||
code: 'type x = { a: string }' | ||
}, | ||
{ | ||
code: 'type x = { a: boolean }' | ||
}, | ||
{ | ||
code: '(x: number) => {}' | ||
}, | ||
{ | ||
code: '(x: string) => {}' | ||
}, | ||
{ | ||
code: '(x: boolean) => {}' | ||
} | ||
] | ||
}; |
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