yegor256 / qulice

Quality Police for Java projects: aggregator of Checkstyle and PMD
https://www.qulice.com
Other
301 stars 111 forks source link

Custom rules #507

Closed androidfred closed 8 years ago

androidfred commented 8 years ago

AS A Dev using Qulice.

I WANT To customize the preconfigured rules.

SO THAT Rules I want enforced but are not in Qulice are enforced, rules I don't want enforced are not enforced.

EG

<configuration>
  <checkstyle>file:${basedir}/checks.xml</checkstyle>
  <pmd>file:${basedir}/ruleset.xml</pmd>
<configuration>

OR

<configuration>
  <excludes>
    <exclude>checkstyle.JavadocMethod:/src/examples/.*</exclude>
    <exclude>findbugs.UC_USELESS_OBJECT:~com.qulice.foo.*</exclude>
  </excludes>
<configuration>

MISC Apologies if this is already possible and I'm missing something. (I browsed through the docs but could find anything that suggests this is supported)

krzyk commented 8 years ago

@androidfred Qulice is a set of preconfigured rules (checkstyle, PMD, FindBugs and others) so we won't add option to disable them in general. But you can use exclude tags from pmd @SuppressWarnings("PMD.SomeRule") or for checkstyle a comment like: @checkstyle LineLength (3 lines) (this comment can be in javadoc or it can be a standalone comment), and findbugs allows: @SuppresFBWarnings("UC_USELESS_OBJECT") (but you need to add findbugs-annotations to the project).

androidfred commented 8 years ago

@krzyk Options for disabling rules have, as mentioned, already been added. The request is simply to improve what's already an option.

Already added options are either too blunt (exclude turns off all rules in the check) or too granular. (annotations/comments have to be unnecessarily added everywhere)

@yegor256 Please consider adding this.

androidfred commented 8 years ago

Look at below source. (never mind what it does)

package io.github.androidfred.verified;

public class NotNull<T> {
    private T object;
    private NotNull() {
    }
    public NotNull(final T object) {
        if (object == null) {
            throw new IllegalArgumentException("Must not be null");
        }
        this.object = object;
    }
    public final T provide() {
        return this.object;
    }
}

Total lines including trailing whitespaces etc: 17. Scrolling not required, can be taken in with a quick glance.

Below is same source but with added stuff required by a few of the rules currently preconfigured in Qulice. Still 17 lines of actual source, but total lines including trailing whitespaces etc: 69. (an over 400% increase) Severe negative impact on readability: requires scrolling and mental filtering out of junk in order to take in.

But my intention is not to criticize the rules currently preconfigured in Qulice. There is nothing wrong with the currently preconfigured rules- it's just that different individuals, teams and projects have different requirements and standards when it comes to rules, which is exactly the point: it would be great if Qulice supported custom rules.

/**
 * This is free and unencumbered software released into the public domain.
 *
 * Anyone is free to copy, modify, publish, use, compile, sell, or
 * distribute this software, either in source code form or as a compiled
 * binary, for any purpose, commercial or non-commercial, and by any
 * means.
 *
 * In jurisdictions that recognize copyright laws, the author or authors
 * of this software dedicate any and all copyright interest in the
 * software to the public domain. We make this dedication for the benefit
 * of the public at large and to the detriment of our heirs and
 * successors. We intend this dedication to be an overt act of
 * relinquishment in perpetuity of all present and future rights to this
 * software under copyright law.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * For more information, please refer to <http://unlicense.org>
 */

package io.github.androidfred.verified;

/**
 * Not null. Throws IllegalArgumentException if something is null.
 * Use: new NotNull(something);
 * @author Fredrik Friis (androidfred@github.com)
 * @version $Id$
 * @param <T> Not null object
 */
public class NotNull<T> {

    /**
     * Not null object.
     */
    private T object;

    /**
     * Disallow use of implicit constructor.
     */
    private NotNull() {
    }

    /**
     * Default and only constructor.
     * @param object Not null Object
     */
    public NotNull(final T object) {
        if (object == null) {
            throw new IllegalArgumentException("Must not be null");
        }
        this.object = object;
    }

    /**
     * Provide not null object.
     * @return Not null object.
     */
    public final T provide() {
        return this.object;
    }
}
krzyk commented 8 years ago

@androidfred same here, see https://github.com/teamed/qulice/issues/326#issuecomment-58991903

androidfred commented 8 years ago

@krzyk Sorry, I didn't see https://github.com/teamed/qulice/issues/326 before I created my duplicate.

the idea of Qulice is to give you not just a tool but a set of best practices to follow.

I understand and agree with this. However I still urge you to consider the request and the example. As has hopefully been made clear, at least some of the rules are not necessarily a matter of best practice, right or wrong, but taste or context.

yegor256 commented 8 years ago

@androidfred as @krzyk mentioned, qulice is intentionally not configurable in that aspect. The example you showed above actually proves our point. The second piece of code looks perfect to me, while the first one is "naked". That's because I'm used to qulice style. All projects, where qulice is used, look the same. And this is an achievement :) If you really need just some Checkstyle/PMD rules, you can always configure them yourself in your pom.xml. I'm sure you know how to do it and it's not difficult.

krzyk commented 8 years ago

@davvd this is invalid

krzyk commented 8 years ago

@davvd this is invalid

krzyk commented 8 years ago

@davvd the issue is invalid

krzyk commented 8 years ago

@davvd it is invalid

krzyk commented 8 years ago

@yegor256 could you help me with invalidating this issue?

yegor256 commented 8 years ago

@krzyk it's not an "issue" yet for us, since it was not accepted yet (you didn't label it as a "bug"). Just ask its author to close it and that's it.

krzyk commented 8 years ago

@androidfred please close this issue

androidfred commented 8 years ago

Thanks for the feedback, closing.