2323
2424` path ` - Files or directory to transform.
2525
26-
2726For more information on jscodeshift, check their official [ docs] ( https://github.com/facebook/jscodeshift ) .
2827
2928## Transforms
@@ -49,3 +48,76 @@ module.exports = {
4948 create : function (context ) { ... }
5049};
5150```
51+
52+ ### v9-rule-migration
53+
54+ Transform that migrates an ESLint rule definition from the old Rule API:
55+
56+ ``` javascript
57+ module .exports = {
58+ create (context ) {
59+ return {
60+ Program (node ) {
61+ const sourceCode = context .getSourceCode ();
62+ const cwd = context .getCwd ();
63+ const filename = context .getFilename ();
64+ const physicalFilename = context .getPhysicalFilename ();
65+ const sourceCodeText = context .getSource ();
66+ const sourceLines = context .getSourceLines ();
67+ const allComments = context .getAllComments ();
68+ const nodeByRangeIndex = context .getNodeByRangeIndex ();
69+ const commentsBefore = context .getCommentsBefore (node);
70+ const commentsAfter = context .getCommentsAfter (node);
71+ const commentsInside = context .getCommentsInside (node);
72+ const jsDocComment = context .getJSDocComment ();
73+ const firstToken = context .getFirstToken (node);
74+ const firstTokens = context .getFirstTokens (node);
75+ const lastToken = context .getLastToken (node);
76+ const lastTokens = context .getLastTokens (node);
77+ const tokenAfter = context .getTokenAfter (node);
78+ const tokenBefore = context .getTokenBefore (node);
79+ const tokenByRangeStart = context .getTokenByRangeStart (node);
80+ const getTokens = context .getTokens (node);
81+ const tokensAfter = context .getTokensAfter (node);
82+ const tokensBefore = context .getTokensBefore (node);
83+ const tokensBetween = context .getTokensBetween (node);
84+ const parserServices = context .parserServices ;
85+ },
86+ };
87+ },
88+ };
89+ ```
90+
91+ to the new [ Rule API introduced in ESLint 9.0.0] ( https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/ ) :
92+
93+ ``` javascript
94+ module .exports = {
95+ create (context ) {
96+ const sourceCode = context .sourceCode ?? context .getSourceCode ();
97+ return {
98+ Program (node ) {
99+ const sourceCodeText = sourceCode .getText ();
100+ const sourceLines = sourceCode .getLines ();
101+ const allComments = sourceCode .getAllComments ();
102+ const nodeByRangeIndex = sourceCode .getNodeByRangeIndex ();
103+ const commentsBefore = sourceCode .getCommentsBefore (nodeOrToken);
104+ const commentsAfter = sourceCode .getCommentsAfter (nodeOrToken);
105+ const commentsInside = sourceCode .getCommentsInside (nodeOrToken);
106+ const jsDocComment = sourceCode .getJSDocComment ();
107+ const firstToken = sourceCode .getFirstToken (node);
108+ const firstTokens = sourceCode .getFirstTokens (node);
109+ const lastToken = sourceCode .getLastToken (node);
110+ const lastTokens = sourceCode .getLastTokens (node);
111+ const tokenAfter = sourceCode .getTokenAfter (node);
112+ const tokenBefore = sourceCode .getTokenBefore (node);
113+ const tokenByRangeStart = sourceCode .getTokenByRangeStart (node);
114+ const getTokens = sourceCode .getTokens (node);
115+ const tokensAfter = sourceCode .getTokensAfter (node);
116+ const tokensBefore = sourceCode .getTokensBefore (node);
117+ const tokensBetween = sourceCode .getTokensBetween (node);
118+ const parserServices = sourceCode .parserServices ;
119+ },
120+ };
121+ },
122+ };
123+ ` ` `
0 commit comments