Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color literals count as single character towards line count #830

Merged
merged 9 commits into from
Oct 14, 2016
Merged

Color literals count as single character towards line count #830

merged 9 commits into from
Oct 14, 2016

Conversation

VFUC
Copy link
Contributor

@VFUC VFUC commented Oct 7, 2016

Hey! Trying to work on issue #742 - I've added a check for an expanded color literal substring when counting line characters. If found, it subtracts the length of the substring (-1) from the total line length, so that a color literal only counts as a single character towards the line count rule. Feedback welcome 🙂

@norio-nomura norio-nomura added the enhancement Ideas for improvements of existing features and rules. label Oct 8, 2016
Copy link
Collaborator

@norio-nomura norio-nomura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @VFUC, the changes mostly look good.
Could you please fix my feedback and add following?

  • examples containing color literal in nonTriggeringExamples and triggeringExamples
  • an enhancement entry in CHANGELOG.md

locale: nil) {

// Range was found, get substring of color literal range
let colorLiteralContent = line.content.substringWithRange(colorLiteralRangeStart.startIndex..<colorLiteralRangeEnd.endIndex)
Copy link
Collaborator

@norio-nomura norio-nomura Oct 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SwiftLintFrameworkTests.IntegrationTests fails that lint codes of SwiftLint itself by SwiftLint.
This line causes violation of line_length rule.
Other lines cause autocorrections of trailing_whitespace rule.
screenshot 2016-10-08 19 03 13

Could you please fix them?

@VFUC
Copy link
Contributor Author

VFUC commented Oct 9, 2016

Thanks for the feedback, I've added the requested changes. I have also modified the general approach to support multiple color literals in a single line.

@codecov-io
Copy link

codecov-io commented Oct 9, 2016

Current coverage is 84.01% (diff: 96.15%)

Merging #830 into master will increase coverage by 0.07%

@@             master       #830   diff @@
==========================================
  Files           101        101          
  Lines          4035       4060    +25   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           3387       3411    +24   
- Misses          648        649     +1   
  Partials          0          0          

Powered by Codecov. Last update 2efa8de...ae942d4

Copy link
Collaborator

@norio-nomura norio-nomura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for changes.

I have also modified the general approach to support multiple color literals in a single line.

Looks good to me 👍 other than indentation and 2 trailing spaces.

options: .LiteralSearch,
range: colorLiteralRangeStart.startIndex..<line.content.endIndex,
range: rangeStart.startIndex..<string.endIndex,
locale: nil) {
Copy link
Collaborator

@norio-nomura norio-nomura Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add indent to lines between let rangeEnd… and locale:nil) {?

@@ -17,6 +17,10 @@
[Norio Nomura](https://github.com/norio-nomura)
[Syo Ikeda](https://github.com/ikesyo)

* Color literals count as single characters to avoid unintentional line length violations.
Copy link
Collaborator

@norio-nomura norio-nomura Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add 2 trailing spaces to this line for making Markdown adds line ending?

@marcelofabri
Copy link
Collaborator

Maybe this should be improved to handle other literals (such as image ones)?

@VFUC
Copy link
Contributor Author

VFUC commented Oct 13, 2016

I have now extracted the literal stripping into a function and applied it for color and image literals (as suggested by @marcelofabri , thanks for that!). If future literals keep the same #...literal() structure, adding them should be easy.

I've also added the requested formatting.

@norio-nomura norio-nomura merged commit 96b1d73 into realm:master Oct 14, 2016
@norio-nomura
Copy link
Collaborator

Thanks for doing this! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants