Skip to content

Latest commit

 

History

History
634 lines (487 loc) · 12.6 KB

AVAILABLE_RULES.md

File metadata and controls

634 lines (487 loc) · 12.6 KB

Available rules

🛈 Common rules are the ones that potentionally could be used in more than single extension (at least two)

📐Common

Rule 📌 Config example ⚙️ Description ⚙️

ComparisionOperatorLevel

(config definition)

{
    "allowedLevels": [1, 2]
}

tests equality/inequality level. Has three levels. Due to the fact that PHP also includes strict/weak equality/inequality feature, it was placed in common category.

FixedLoopLengthCondition

(config definition)

{
    "regex": "(\\w+).length"
}

designed to check for/while/do..while loops and comment out .length reference in condition statement. Expression can be adjusted to e.g. fit other language length calling.

KeywordsOrderedByLength

(config definition)

{
    "keywords": [
        {
            "name": "import (packages)",
            "regex": "import.*(?:from(?!.*[@,.]/)|{)",
            "order": "ascending",
            "ignoreNewline": false,
            "multiLineOptions": [
                {
                    "indicator": {
                        "notIncludes": "from"
                    },
                    "limiter": {
                        "regex": "from(?!.*[@,.]/)"
                    }
                }
            ]
        },
        {
            "name": "import (files)",
            "regex": "import.*(?:from.*[@,.]/|{)",
            "order": "ascending",
            "ignoreNewline": false,
            "multiLineOptions": [
                {
                    "indicator": {
                        "notIncludes": "from"
                    },
                    "limiter": {
                        "regex": "from.*[@,.]/"
                    }
                }
            ]
        }
    ]
}

tests configured keywords order. If there is a need in ordering packages and other imports separately, try to define two distinct keywords. In provided example (at) is used to differentiate two groups.

LineBreakBeforeReturn

checks whether `return` statements should be preceded with line-break.

MarkedComments

(config definition)

{
    "prefixes": [
        {
            "value": "@TODO",
            "meaning": "not implemented feature"
        }
    ],
    "isAppliedToSingleLineComments": true,
    "isAppliedToMultiLineComments": true,
    "isAppliedToInlineComments": true
}

reviews whether // or /* */ comments start with at least one of the predefined prefixes. Combine it with e.g. Better Comments extension.

PositionedKeywords

(config definition)

{
    "keywords": [
        {
            "name": "import",
            "regex": "import.*(?:from|{)",
            "position": {
                "BOF": true,
                "custom": null
            },
            "maxLineBreaks": 0,
            "enforced": true,
            "breakOnFirstOccurence": false,
            "countDifferentCodeAsLineBreak": false,
            "multiLineOptions": [
                {
                    "indicator": {
                        "notIncludes": "from"
                    },
                    "limiter": {
                        "startsWith": "} from"
                    }
                }
            ],
            "order": [
                {
                    "name": "packages",
                    "regex": "from(?!.*[@,.]/)"
                },
                {
                    "name": "others",
                    "regex": "from.*[@,.]/"
                }
            ]
        }
    ]
}

tests configured keywords position. Position can be BOF (beginning of file) or custom. If default position is not found (and keyword has enforced flag set to true), first matched occurence of keyword is used as position. It's highly recommended to use enforced flag as in 99% cases patches won't contain first line.

PredefinedFilenames

(config definition)

{
    "restrictions": [
        {
            "path": "backend/src/controllers/*",
            "expectedName": ".*Controller.js"
        }
    ]
}

checks names of files based on configured restrictions. For instance files in backend/controllers/* could be restricted with [a-z].*Controller.js regex.

SingleLineBlockPattern

(config definition)

tests single line blocks curly braces presence depending on configuration. Config not included due to complicated structure.

⚠️ If you want to include that rule, copy config from default rules file which you can find here.

📐HTML

Rule 📌 Config example ⚙️ Description ⚙️

MarkedComments

(config definition)

{
    "prefixes": [
        {
            "value": "@TODO",
            "meaning": "not implemented feature"
        }
    ]
}

test whether <!-- --> comments start with at least one of the configured prefixes.

JavaScript

Rule 📌 Config example ⚙️ Description ⚙️

AsynchronousPattern

(config definition)

{
    "pattern": "await"
}

tests whether configured asynchronous pattern is used.

ImplicitIndexFileImport

(config definition)

{
    "type": "commonjs"
}

ensures that import/require statements that target index file are not referenced explictly.

ImportWithoutExtension

(config definition)

{
    "type": "module"
}

checks whether import or require statements do not end with extension.

IndividualMethodImport

(config definition)

{
    "packages": [
        {
            "name": "lodash",
            "regex": "[(|'|\"|`]lodash[)|'|\"|`]"
        }
    ]
}

allows to define set of packages which methods should be imported/required one by one e.g. `lodash`.

SimpleComparision

(config definition)

{
    "patterns": [
        {
            "name": "ne (-1)",
            "regex": "!={1,2}(\\s)*?-1",
            "comment": "`value !== -1` -> `~value`"
        }
    ]
}

allows to define simple patterns that are expected to have simplified form like test !== -1 -> ~test.

SimplePropertyAssignment

looks after redundant value assignment to property of the same name e.g. test1: test1.

Pull

Rule 📌 Config example ⚙️ Description ⚙️

StrictWorkflow

(config definition)

{
    "workflow": [
        {
            "base": "master",
            "head": "release"
        },
        {
            "base": "develop",
            "head": "release"
        },
        {
            "base": "develop",
            "head": "feature"
        },
        {
            "base": "master",
            "head": "hotfix"
        },
        {
            "base": "develop",
            "head": "hotfix"
        }
    ],
    "abortReviewOnInvalidFlow": false,
    "abortReviewOnInvalidBranchPrefix": false
}

checks workflow of issued pull request and prefix of the branch. Can be configured to abort further (files) review.

Vue

Rule 📌 Config example ⚙️ Description ⚙️

NormalizedEventHandler

(config definition)

{
    "prefix": "on",
    "noUnnecessaryBraces": true
}

allows to configure prefix of event declaration. Can also be configured to comment out unnecessary braces usage e.g. @click="onClick()"`.

SelfClosingTag

comments out tags that are not self-closed but have no content.