Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon committed Sep 20, 2024
1 parent 4983c8f commit d648027
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions cmd/tlin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
})
default:
runWithTimeout(ctx, func() {
runNormalLintProcess(ctx, logger, engine, config.Paths)
runNormalLintProcess(ctx, logger, engine, config.Paths, false)
})
}
}
Expand Down Expand Up @@ -137,17 +137,32 @@ func runWithTimeout(ctx context.Context, f func()) {
}
}

func runNormalLintProcess(ctx context.Context, logger *zap.Logger, engine LintEngine, paths []string) {
issues, err := processFiles(ctx, logger, engine, paths, processFile)
if err != nil {
logger.Error("Error processing files", zap.Error(err))
os.Exit(1)
}
func runNormalLintProcess(ctx context.Context, logger *zap.Logger, engine LintEngine, paths []string, isWatching bool) {
for {
issues, err := processFiles(ctx, logger, engine, paths, processFile)
if err != nil {
logger.Error("error processing files", zap.Error(err))
if !isWatching {
os.Exit(1)
}
}

printIssues(logger, issues)
printIssues(logger, issues)

if len(issues) > 0 {
os.Exit(1)
if !isWatching {
if len(issues) > 0 {
os.Exit(1)
}
return
}

select {
case <-ctx.Done():
logger.Info("watch mode stopped")
return
case <-time.After(5 * time.Second):
// wait 5 seconds and check again
}
}
}

Expand Down Expand Up @@ -214,6 +229,7 @@ func runAutoFix(ctx context.Context, logger *zap.Logger, engine LintEngine, path
}

func runWatchMode(ctx context.Context, logger *zap.Logger, engine *internal.Engine, paths []string) {
isWatching := true
err := engine.StartWatching()
if err != nil {
logger.Fatal("failed to start watching", zap.Error(err))
Expand All @@ -223,7 +239,7 @@ func runWatchMode(ctx context.Context, logger *zap.Logger, engine *internal.Engi
logger.Info("watch mode started. press ctrl+c (or, cmd+c on mac) to stop.")

// start initial lint process
runNormalLintProcess(ctx, logger, engine, paths)
runNormalLintProcess(ctx, logger, engine, paths, isWatching)

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
Expand Down

0 comments on commit d648027

Please sign in to comment.