Skip to content

Commit

Permalink
Add --unvalidated option + fix performance measuring caching issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Apr 9, 2023
1 parent 4a3f7aa commit a18ae2b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se

## [Unreleased]
### Added
- None.
- Added a new `--unvalidated` (`-u`) option for running all checks without running the validations provided, such as testing for `matchingExamples` and `nonMatchingExamples`. Use with cuation.
### Changed
- None.
- Some internal code clean-up.
- Upgrade to Swift 5.7 manifest syntax.
### Deprecated
- None.
### Removed
- None.
### Fixed
- None.
- The `--measure` option also measured validations & files search which distorted the measure time for the first check with the same files search. Now, it only measures the actual matching time of the Regex for better evaluation.
### Security
- None.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ There are also several flags you can pass to `anylint`:
1. `-s` / `--strict`: Fails on warnings as well. (By default, the command only fails on errors.)
1. `-x` / `--xcode`: Prints warnings & errors in a format to be reported right within Xcodes left sidebar.
1. `-l` / `--validate`: Runs only validations for `matchingExamples`, `nonMatchingExamples` and `autoCorrectExamples`.
1. `-u` / `--unvalidated`: Runs the checks without validating their correctness. Only use for faster subsequent runs after a validated run succeeded.
1. `-m` / `--measure`: Prints the time it took to execute each check for performance optimizations.
1. `-v` / `--version`: Prints the current tool version. (Does not run any lint checks.)
1. `-d` / `--debug`: Logs much more detailed information about what AnyLint is doing for debugging purposes.
Expand Down
44 changes: 24 additions & 20 deletions Sources/AnyLint/Lint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum Lint {
autoCorrectExamples: [AutoCorrection] = [],
repeatIfAutoCorrected: Bool = false
) throws {
try Statistics.shared.measureTime(check: checkInfo) {
if !Options.unvalidated {
validate(regex: regex, matchesForEach: matchingExamples, checkInfo: checkInfo)
validate(regex: regex, doesNotMatchAny: nonMatchingExamples, checkInfo: checkInfo)

Expand All @@ -47,18 +47,20 @@ public enum Lint {
autocorrectReplacement: autoCorrectReplacement
)
}
}

guard !Options.validateOnly else {
Statistics.shared.executedChecks.append(checkInfo)
return
}
guard !Options.validateOnly else {
Statistics.shared.executedChecks.append(checkInfo)
return
}

let filePathsToCheck: [String] = FilesSearch.shared.allFiles(
within: fileManager.currentDirectoryPath,
includeFilters: includeFilters,
excludeFilters: excludeFilters
)
let filePathsToCheck: [String] = FilesSearch.shared.allFiles(
within: fileManager.currentDirectoryPath,
includeFilters: includeFilters,
excludeFilters: excludeFilters
)

try Statistics.shared.measureTime(check: checkInfo) {
let violations = try FileContentsChecker(
checkInfo: checkInfo,
regex: regex,
Expand Down Expand Up @@ -95,7 +97,7 @@ public enum Lint {
autoCorrectExamples: [AutoCorrection] = [],
violateIfNoMatchesFound: Bool = false
) throws {
try Statistics.shared.measureTime(check: checkInfo) {
if !Options.unvalidated {
validate(regex: regex, matchesForEach: matchingExamples, checkInfo: checkInfo)
validate(regex: regex, doesNotMatchAny: nonMatchingExamples, checkInfo: checkInfo)
validateParameterCombinations(
Expand All @@ -113,18 +115,20 @@ public enum Lint {
autocorrectReplacement: autoCorrectReplacement
)
}
}

guard !Options.validateOnly else {
Statistics.shared.executedChecks.append(checkInfo)
return
}
guard !Options.validateOnly else {
Statistics.shared.executedChecks.append(checkInfo)
return
}

let filePathsToCheck: [String] = FilesSearch.shared.allFiles(
within: fileManager.currentDirectoryPath,
includeFilters: includeFilters,
excludeFilters: excludeFilters
)
let filePathsToCheck: [String] = FilesSearch.shared.allFiles(
within: fileManager.currentDirectoryPath,
includeFilters: includeFilters,
excludeFilters: excludeFilters
)

try Statistics.shared.measureTime(check: checkInfo) {
let violations = try FilePathsChecker(
checkInfo: checkInfo,
regex: regex,
Expand Down
1 change: 1 addition & 0 deletions Sources/AnyLint/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import Foundation

enum Options {
static var validateOnly: Bool = false
static var unvalidated: Bool = false
}
4 changes: 4 additions & 0 deletions Sources/AnyLintCLI/Commands/SingleCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class SingleCommand: Command {
@Flag("-l", "--validate", description: "Runs only validations for `matchingExamples`, `nonMatchingExamples` and `autoCorrectExamples`.")
var validate: Bool

@Flag("-u", "--unvalidated", description: "Runs the checks without validating their correctness. Only use for faster subsequent runs after a validated run succeeded.")
var unvalidated: Bool

@Flag("-m", "--measure", description: "Prints the time it took to execute each check for performance optimizations")
var measure: Bool

Expand Down Expand Up @@ -74,6 +77,7 @@ class SingleCommand: Command {
logDebugLevel: self.debug,
failOnWarnings: self.strict,
validateOnly: self.validate,
unvalidated: self.unvalidated,
measure: self.measure
).perform()
} catch LintTask.LintError.configFileFailed {
Expand Down
5 changes: 5 additions & 0 deletions Sources/AnyLintCLI/Tasks/LintTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct LintTask {
let logDebugLevel: Bool
let failOnWarnings: Bool
let validateOnly: Bool
let unvalidated: Bool
let measure: Bool
}

Expand Down Expand Up @@ -42,6 +43,10 @@ extension LintTask: TaskHandler {
command += " \(Constants.validateArgument)"
}

if unvalidated {
command += " \(Constants.unvalidatedArgument)"
}

if measure {
command += " \(Constants.measureArgument)"
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/Utility/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public enum Constants {
/// The validate-only mode argument for command-line pass-through.
public static let validateArgument: String = "validate"

/// The unvalidated mode argument for command-line pass-through.
public static let unvalidatedArgument: String = "unvalidated"

/// The measure mode to see how long each check took to execute
public static let measureArgument: String = "measure"

Expand Down

0 comments on commit a18ae2b

Please sign in to comment.