realm / realm/SwiftLint

Using --strict --fix hides errors and succeeds

Open
#5,387 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
Describe the bug

We are using swiftlint with pre-commit with the command provided in the documentation

  - repo: https://github.com/realm/SwiftLint
    rev: 0.54.0
    hooks:
      - id: swiftlint
        entry: swiftlint --fix --strict

It does fix the issues but it does not fail.

changing to just swiftlint fails as expected but doesn't fix the issues

Complete output when running SwiftLint, including the stack trace and command used

with swiftlint --fix --strict

$ gc -a

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...............................................................Passed
check json...........................................(no files to check)Skipped
check for added large files..............................................Passed
check that executables have shebangs.................(no files to check)Skipped
check that scripts with shebangs are executable..........................Passed
detect private key.......................................................Passed
forbid submodules....................................(no files to check)Skipped
mixed line ending........................................................Passed
SwiftLint................................................................Passed
SwiftFormat..............................................................Passed

just with swiftlint

$ git commit -a
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...............................................................Passed
check json...........................................(no files to check)Skipped
check for added large files..............................................Passed
check that executables have shebangs.................(no files to check)Skipped
check that scripts with shebangs are executable..........................Passed
detect private key.......................................................Passed
forbid submodules....................................(no files to check)Skipped
mixed line ending........................................................Passed
SwiftLint................................................................Failed
- hook id: swiftlint
- exit code: 2

Linting Swift files at paths Modules/DesignKit/Sources/Colors.swift
Linting 'Colors.swift' (1/1)
/Users/ladislas/dev/leka/ios-monorepo/Modules/DesignKit/Sources/Colors.swift
⛔️ Line 10: Variable name 'arr' should be between 4 and 40 characters long (identifier_name)
⛔️ Line 8: Type name 'leka' should start with an uppercase character (type_name)
Done linting! Found 2 violations, 2 serious in 1 file.

SwiftFormat..............................................................Passed
Environment
  • SwiftLint version (run swiftlint version to be sure)?
swiftlint version
0.53.0
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?

Homebrew

  • Paste your configuration file:
# Leka - iOS Monorepo
# Copyright 2023 APF France handicap
# SPDX-License-Identifier: Apache-2.0

opt_in_rules: []

trailing_comma:
  mandatory_comma: true

type_name:
  min_length: 4 # only warning
  max_length: # warning and error
    warning: 40
    error: 50
  allowed_symbols: ["_"] # these are allowed in type names
  excluded:
    - i18n
    - l10n

identifier_name:
  min_length: # only min_length
    error: 4 # only error
  excluded:
    - a
    - app
    - args
    - b
    - ble
    - BLE
    - cmd
    - g
    - i
    - i18n
    - id
    - img
    - key
    - l10n
    - lhs
    - log
    - new
    - r
    - red
    - rgb
    - rhs
    - rx
    - tx
    - URL

line_length:
  warning: 150
  ignores_urls: true
  ignores_function_declarations: true
  ignores_interpolated_strings: true

disabled_rules:
  - opening_brace
  - switch_case_alignment
  - closure_parameter_position

excluded:
  - Tuist/Dependencies
  - ./*/Derived

reporter: "emoji"

no

  • Which Xcode version are you using (check xcodebuild -version)?
xcodebuild -version
Xcode 15.0.1
Build version 15A507
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.

It involves using pre-commit, so no

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SwiftLint command-line handling for swiftlint --fix --strict, reproducing the behavior with the pre-commit entry shown in the issue and with plain swiftlint. Done means autofixing still occurs while remaining violations cause a failing exit status, as they do without --fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.