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

Suppress all/specific rules for a given file #328

Closed
krzema12 opened this issue Jan 12, 2019 · 2 comments
Closed

Suppress all/specific rules for a given file #328

krzema12 opened this issue Jan 12, 2019 · 2 comments

Comments

@krzema12
Copy link

krzema12 commented Jan 12, 2019

In my projects, in unit tests, I use a library that requires adding some extra spaces, to align strings and other values with each other, for example:

    @Test
    fun sineWaveFor1Hz() {
        assertFunctionConformsTo(
                functionUnderTest = sineWave(1.0f),
                visualisation = {
                    row(1.0f,   "               IIIIIXIIIII                                                       ")
                    row(        "          IIIII           IIIII                                                  ")
                    row(        "       III                     III                                               ")
                    row(        "    III                           III                                            ")
                    row(        "  II                                 II                                          ")
                    row(0.0f,   "XI                                     III                                     II")
                    row(        "                                          II                                 II  ")
                    row(        "                                            III                           III    ")
                    row(        "                                               III                     III       ")
                    row(        "                                                  IIIII           IIIII          ")
                    row(-1.0f,  "                                                       IIIIIXIIIII               ")
                    xAxis {
                        markers("|                   |                   |                   |                   |")
                        values( 0.0f,               0.25f,              0.5f,               0.75f,              1.0f)
                    }
                })
    }

You can see that e.g. after most row(, some extra spaces are added. Also in values function call, parameters are aligned in a peculiar way. Ktlint doesn't like it and I understand it.

What I would like to achieve is to disable no-multi-spaces and paren-spacing checks for a given .kt file. This way I could have Ktlint checks also in my unit tests, excluding these two checks to allow special formatting required by assertFunctionConformsTo. Currently I told Ktlint to omit checking unit tests.

I tried adding e.g. package it.krzeminski.fsynth // ktlint-disable, but it doesn't work at all. Suppressing a specific error doesn't work as well.

krzema12 added a commit to fsynthlib/fsynth that referenced this issue Jan 12, 2019
Checks for tests are omitted because of peculiar formatting required
by PlotAssert. See pinterest/ktlint#328
for details.

Part of #32.
@shyiko
Copy link
Collaborator

shyiko commented Feb 12, 2019

/* ktlint-disable no-multi-spaces paren-spacing */
    @Test
    fun sineWaveFor1Hz() {
        assertFunctionConformsTo(
                functionUnderTest = sineWave(1.0f),
                visualisation = {
                    row(1.0f,   "               IIIIIXIIIII                                                       ")
                    row(        "          IIIII           IIIII                                                  ")
                    row(        "       III                     III                                               ")
                    row(        "    III                           III                                            ")
                    row(        "  II                                 II                                          ")
                    row(0.0f,   "XI                                     III                                     II")
                    row(        "                                          II                                 II  ")
                    row(        "                                            III                           III    ")
                    row(        "                                               III                     III       ")
                    row(        "                                                  IIIII           IIIII          ")
                    row(-1.0f,  "                                                       IIIIIXIIIII               ")
                    xAxis {
                        markers("|                   |                   |                   |                   |")
                        values( 0.0f,               0.25f,              0.5f,               0.75f,              1.0f)
                    }
                })
    }
/* ktlint-disable no-multi-spaces paren-spacing */

should do it.
That being said, ability to disable rules on per-file basis is coming in #208.

@shyiko shyiko closed this as completed Feb 12, 2019
@krzema12
Copy link
Author

Thanks, that is enough for me for now. However, +1 to #208.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants