Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

feat: add rule to notify on using a double space #65

Merged
merged 19 commits into from
May 9, 2020

Conversation

Chesire
Copy link
Owner

@Chesire Chesire commented May 8, 2020

Add a Gradle and XML rule that will notify if a double space is detected. This required a little refactor to add some form of shared code, so now the modules have a common module added as a sourceSet.
Trying to add the module itself as a dependency to the main modules seemed to have caused issues, so a sourceset seems to be the way to make it work.

Chesire added 15 commits May 8, 2020 15:33
The common module will house any shared code for the other modules, such as shared Issue classes
Since issues in the common space will need to share their details with other issues in the other
modules, add a new interface that allows any other issues to implement to store its basic info. In
this case the MultipleSpaceIssue will implement the LintIssue to set the basic details such as
priority and id, and then the MultipleSpaceIssue will be implemented by another class to set the
Issue field
Add the initial issue object, and the detector file
Check through all the lines in a Gradle file to find any instances of "  ", if it is found raise an
error for that line
Using a regex is much less code and allows easily finding the exact location of where the issues
occur
Currently the regex to find spaces will check for word characters, but it should be checking for
anything that is not a white space to ensure that something like `.  words` is also picked up
Add a test for the failure case and a test for the success case
Add a matching issue detector for multiple spaces for the xml module as well, currently this is a
duplicated file, it will be worth trying to share the same detector across both modules
Add a base detector so that both of the MultipleSpaceDetector can use some shared discovery code,
this is a bit nicer than having them both completely written, but I feel there could be some updates
here to make less verbose in each
The common module needs to be setup with Detekt
Add test to ensure the correct issues are present
The test application needs to be updated for the latest checks
It looks like the lint checks won't work in the test module, they won't work if they are
set to compileOnly either. To get around this, make the common module a sourceSet in
each of the other modules.
@Chesire Chesire self-assigned this May 8, 2020
@commit-lint
Copy link

commit-lint bot commented May 8, 2020

Features

  • add a common module for issues that can span other modules (b7f4d48)
  • add new interface for the issues to derive from (05d7a73)
  • add initial files for the MultipleSpace issue in the gradle module (4ec3deb)
  • add the MultipleSpace issue to the registry (804ad9f)
  • raise lint rule violation when finding an instance of double space (0b35efc)
  • add finding multiple spaces in xml files (00a1987)

Documentation

  • add missing kdoc for the base LintIssue (7d4580f)

Code Refactoring

  • change to use regex for finding double spaces (88c6268)
  • add a base detector for each MultipleSpaceDetector (37a447c)
  • change the severity level of the MultipleSpace issue (7028e99)
  • use the common module to share more code (303b7f5)
  • increase the offsets before sending to report (c45d859)

Bug Fixes

  • regex should account for all characters other than whitespace (5d11365)
  • lint checks not working in test module (fc6e2a3)

Tests

  • add tests for the MultipleSpaceDetector (1e66368)
  • add tests to the LintRegistrys (fae402c)

Chore

  • make the common module run on detekt as well (3964bf6)
  • update the test app (b3a2cf1)
  • update readme (c825a76)

Contributors

@Chesire

@Chesire
Copy link
Owner Author

Chesire commented May 8, 2020

There should be some way to share the whole detector and issue, instead of having two implementations

@Chesire
Copy link
Owner Author

Chesire commented May 8, 2020

Maybe if the common module had the entire implementation in it, maybe the LintRegistries could just pull in the issue itself, then users could choose which one (or both) they want to pull in.

Change from the Severity of Information to use a Severity of Warning
A lot of the code was still duplicated between the two modules, move more of the shared logic to
being defined in the BaseMultipleSpaceDetector, with the platform specific ones only needing to
provide the report method. This will still work correctly as each platform has to provide its own
Issue with its own Implementation, so they will still be separated
@Chesire
Copy link
Owner Author

Chesire commented May 9, 2020

More of the logic is now within the shared directory

The consumers shouldn't need to know the increase the offsets when reporting, do it before sending
to the report method
@Chesire
Copy link
Owner Author

Chesire commented May 9, 2020

README also needs to be updated

Update readme to mention the new lint rules
@Chesire Chesire merged commit af6c911 into master May 9, 2020
@Chesire Chesire deleted the feat/double-space-rule branch May 9, 2020 17:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant