Skip to content

Fix all parsing warnings & errors in rule examples #3348

Open

Description

@jpsim

Many rule examples are very succinct, focusing just on the syntax that is meant to be linted/corrected. For example: if foo == nil. However, this doesn't parse successfully:

$ echo "if foo == nil" > file.swift
$ swiftc -parse file.swift
file.swift:1:14: error: expected '{' after 'if' condition
if foo == nil
             ^

In an upcoming PR, I'll want to introduce a change to avoid correcting files if they have parser errors or warnings, since SwiftLint isn't designed to handle all possibilities of invalid Swift code. Generally, it's still useful for SwiftLint to lint Swift files that don't parse 100% cleanly as a feedback mechanism, but we shouldn't attempt to correct files with violations that don't parse cleanly, because that can mangle or delete code in unintended ways.

Because there are currently over 500 rule examples with parser diagnostics, I don't have time to fix all of them, but we probably should do that eventually.

This is a good starter task if someone's interested in contributing to SwiftLint.

Activity

  1. added
    wontfix
    on Nov 16, 2020
  2. deleted a comment from stale on Sep 25, 2022
  3. added
    enhancement
    good first issue
    and removed
    wontfix
    on Sep 25, 2022
  4. lo1tuma commented on Feb 17, 2023

    @lo1tuma
    Contributor

    Generally, it's still useful for SwiftLint to lint Swift files that don't parse 100% cleanly

    What is the reasoning behind this? And does this mean that just SwiftLint should be able to handle invalid code or does this apply for the examples as well. Maybe we could introduce a mechanism to parse all examples and check if there are any parse errors (maybe directly in the Example init method). That way we could make sure all examples are valid while still allowing invalid code to go through SwiftLint.

    I think there is not much value in fixing all those parse errors now, without a way to enforcing examples to be valid. If we don’t enforce it, then we would end up in the same situation again after a while, because examples are added or get modified and might become invalid again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions