@@ -4,6 +4,7 @@ const { dirname, relative } = require("path");
44const {
55 getWorkspaces,
66 isSubPath,
7+ isWorkspacePath,
78 getImport,
89 pathToImport,
910} = require ( "../utils" ) ;
@@ -26,21 +27,25 @@ module.exports.meta = {
2627module . exports . create = ( context ) => {
2728 const workspaces = getWorkspaces ( context ) ;
2829 const filename = context . getFilename ( ) ;
29- return getImport ( workspaces , filename , ( { node, path, start, end } ) => {
30- workspaces . forEach ( ( { package : { name } , location } ) => {
31- if ( isSubPath ( location , filename ) && isSubPath ( name , path ) ) {
32- context . report ( {
33- node,
34- messageId : "noAbsoluteImports" ,
35- fix : ( fixer ) =>
36- fixer . replaceTextRange (
37- [ start + 1 , end - 1 ] ,
38- pathToImport (
39- relative ( dirname ( filename ) , path . replace ( name , location ) ) ,
30+ return getImport (
31+ workspaces ,
32+ filename ,
33+ ( { node, path, value, start, end } ) => {
34+ workspaces . forEach ( ( { package : { name } , location } ) => {
35+ if ( isSubPath ( location , filename ) && isWorkspacePath ( name , value ) ) {
36+ context . report ( {
37+ node,
38+ messageId : "noAbsoluteImports" ,
39+ fix : ( fixer ) =>
40+ fixer . replaceTextRange (
41+ [ start + 1 , end - 1 ] ,
42+ pathToImport (
43+ relative ( dirname ( filename ) , path . replace ( name , location ) ) ,
44+ ) ,
4045 ) ,
41- ) ,
42- } ) ;
43- }
44- } ) ;
45- } ) ;
46+ } ) ;
47+ }
48+ } ) ;
49+ } ,
50+ ) ;
4651} ;
0 commit comments