google / swift

The Swift Programming Language
https://swift.org/
840 stars 66 forks source link

Use the pretty-printer output for whitespace linting #226

Closed dabelknap closed 5 years ago

dabelknap commented 5 years ago

Currently, the way we handle linting for whitespace is to use Stage 1 rules, implemented in Sources/SwiftFormatRules. The pretty-printer now handles all formatting of whitespace in a Swift file. It does not have linting capability, so we have to maintain separate Stage 1 rules for the purposes of linting whitespace.

The changes introduced in this PR use the output of the pretty-printer and compares it to the user's input text to check for whitespace lint errors. This means that any changes we make to the pretty-printer's handling of whitespace will automatically result in the appropriate linter errors without the need to maintain separate Stage 1.

Note: In format mode, the pretty-printer receives the head AST node after the Stage 1 rules have had a chance to transform it. In this situation, we feed an unmodified AST into the pretty-printer. The user's text and the pretty-printer's formatted text must be identical except for whitespace characters.