@@ -21,7 +21,6 @@ package cadence
2121import (
2222 "errors"
2323 "fmt"
24- "path/filepath"
2524 "strings"
2625
2726 "github.com/onflow/flow-cli/internal/util"
@@ -196,11 +195,18 @@ func (l *linter) handleImport(
196195 Elaboration : helpersChecker .Elaboration ,
197196 }, nil
198197 default :
198+ // Normalize relative path imports to absolute paths
199+ if util .IsPathLocation (importedLocation ) {
200+ importedLocation = util .NormalizePathLocation (checker .Location , importedLocation )
201+ }
202+
199203 filepath , err := l .resolveImportFilepath (importedLocation , checker .Location )
200204 if err != nil {
201205 return nil , err
202206 }
203207
208+ fileLocation := common .StringLocation (filepath )
209+
204210 importedChecker , ok := l .checkers [filepath ]
205211 if ! ok {
206212 code , err := l .state .ReadFile (filepath )
@@ -219,7 +225,7 @@ func (l *linter) handleImport(
219225 }
220226 }
221227
222- importedChecker , err = checker .SubChecker (importedProgram , importedLocation )
228+ importedChecker , err = checker .SubChecker (importedProgram , fileLocation )
223229 if err != nil {
224230 return nil , err
225231 }
@@ -246,7 +252,7 @@ func (l *linter) resolveImportFilepath(
246252) {
247253 switch location := location .(type ) {
248254 case common.StringLocation :
249- // If the location is not a cadence file try getting the code by identifier
255+ // Resolve by contract name from flowkit config
250256 if ! strings .Contains (location .String (), ".cdc" ) {
251257 contract , err := l .state .Contracts ().ByName (location .String ())
252258 if err != nil {
@@ -256,14 +262,7 @@ func (l *linter) resolveImportFilepath(
256262 return contract .Location , nil
257263 }
258264
259- // If the location is a cadence file, resolve relative to the parent location
260- parentPath := ""
261- if parentLocation != nil {
262- parentPath = parentLocation .String ()
263- }
264-
265- resolvedPath := filepath .Join (filepath .Dir (parentPath ), location .String ())
266- return resolvedPath , nil
265+ return location .String (), nil
267266 default :
268267 return "" , fmt .Errorf ("unsupported location: %T" , location )
269268 }
0 commit comments