File tree 4 files changed +118
-0
lines changed
4 files changed +118
-0
lines changed Original file line number Diff line number Diff line change
1
+ # No Wildcard Imports
2
+
3
+ ## Rule Details
4
+
5
+ This rule enforces that no sx props are used with ` @primer/react ` .
6
+
7
+ 👎 Examples of ** incorrect** code for this rule
8
+
9
+ ``` jsx
10
+ import {Button } from ' @primer/react'
11
+
12
+ function ExampleComponent () {
13
+ return (
14
+ < Button
15
+ sx= {
16
+ {
17
+ /* ... */
18
+ }
19
+ }
20
+ / >
21
+ )
22
+ }
23
+ ```
24
+
25
+ 👍 Examples of ** correct** code for this rule:
26
+
27
+ ``` jsx
28
+ import {Button } from ' @primer/react'
29
+
30
+ function ExampleComponent () {
31
+ return < Button className= " ..." / >
32
+ }
33
+ ```
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module.exports = {
12
12
'a11y-use-next-tooltip' : require ( './rules/a11y-use-next-tooltip' ) ,
13
13
'use-deprecated-from-deprecated' : require ( './rules/use-deprecated-from-deprecated' ) ,
14
14
'no-wildcard-imports' : require ( './rules/no-wildcard-imports' ) ,
15
+ 'no-sx-prop' : require ( './rules/no-sx-prop' ) ,
15
16
'no-unnecessary-components' : require ( './rules/no-unnecessary-components' ) ,
16
17
'prefer-action-list-item-onselect' : require ( './rules/prefer-action-list-item-onselect' ) ,
17
18
} ,
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const { RuleTester} = require ( 'eslint' )
4
+ const rule = require ( '../no-sx-prop' )
5
+
6
+ const ruleTester = new RuleTester ( {
7
+ parser : require . resolve ( '@typescript-eslint/parser' ) ,
8
+ parserOptions : {
9
+ ecmaVersion : 'latest' ,
10
+ sourceType : 'module' ,
11
+ ecmaFeatures : {
12
+ jsx : true ,
13
+ } ,
14
+ } ,
15
+ } )
16
+
17
+ ruleTester . run ( 'no-sx-prop' , rule , {
18
+ valid : [ `import {Button} from '@primer/react'` ] ,
19
+ invalid : [
20
+ {
21
+ code : `
22
+ import {SegmentedControl} from '@primer/react';
23
+ function Example() {
24
+ return <SegmentedControl sx={{color: 'red'}} />
25
+ }
26
+ ` ,
27
+ errors : [
28
+ {
29
+ messageId : 'sxProp' ,
30
+ } ,
31
+ ] ,
32
+ } ,
33
+ ] ,
34
+ } )
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const url = require ( '../url' )
4
+
5
+ const forbidden = new Set ( [
6
+ 'SegmentedControl' ,
7
+ // 'ActionList',
8
+ // 'ActionList.Divider',
9
+ // 'ActionList.Group',
10
+ // 'ActionList.Item',
11
+ // 'ActionList.LeadingVisual',
12
+ // 'ActionList.LinkItem',
13
+
14
+ // 'UnderlineNav',
15
+ // 'UnderlineNav.Item',
16
+ ] )
17
+
18
+ /**
19
+ * @type {import('eslint').Rule.RuleModule }
20
+ */
21
+ module . exports = {
22
+ meta : {
23
+ type : 'problem' ,
24
+ docs : {
25
+ description : 'The sx prop is discouraged. Use CSS Modules instead' ,
26
+ recommended : true ,
27
+ url : url ( module ) ,
28
+ } ,
29
+ fixable : true ,
30
+ schema : [ ] ,
31
+ messages : {
32
+ sxProp :
33
+ 'The `sx` prop has been deprecated by @primer/react and will be removed in the next major release. Please migrate to CSS Modules instead.' ,
34
+ } ,
35
+ } ,
36
+ create ( context ) {
37
+ return {
38
+ JSXOpeningElement ( node ) {
39
+ if ( ! forbidden . has ( node . name . name ) ) {
40
+ return
41
+ }
42
+
43
+ context . report ( {
44
+ node,
45
+ messageId : 'sxProp' ,
46
+ } )
47
+ } ,
48
+ }
49
+ } ,
50
+ }
You can’t perform that action at this time.
0 commit comments