Skip to content

ilyavolodin/eslint-plugin-backbone

Repository files navigation

NPM version build status

eslint-plugin-backbone

Backbone specific linting rules for ESLint

How to use

Install ESLint either locally or globally

npm install eslint@latest

or

npm install eslint@latest --save-dev

eslint-plugin-backbone version 3.0.0+ requires ESLint with version greater than 9.0.0. To use an older version of ESLint, use eslint-plugin-backbone version 2.1.1.

Install Backbone plugins.

If you installed ESLint globally, you have to install Backbone plugin globally too. Otherwise, install it locally.

npm install eslint-plugin-backbone

or

npm install eslint-plugin-backbone --save-dev

Configuration

In version 3.0.0, configurations upgraded to ESLint flat config.

Using the recommended configuration

import backbone from "eslint-plugin-backbone";

export default [
    backbone.configs.recommended
]

This will enable the rules listed below, as well as add two global variables - Backbone and _.

{
    "collection-model": 2,
    "defaults-on-top": 1,
    "event-scope": 1,
    "events-on-top": [
        1,
        [
            "tagName",
            "className"
        ]
    ],
    "initialize-on-top": [
        1,
        {
            "View": [
                "tagName",
                "className",
                "events"
            ],
            "Model": [
                "defaults",
                "url",
                "urlRoot"
            ],
            "Collection": [
                "model",
                "url"
            ]
        }
    ],
    "model-defaults": 2,
    "no-changed-set": 2,
    "no-collection-models": 2,
    "no-constructor": 1,
    "no-el-assign": 2,
    "no-model-attributes": 2,
    "no-native-jquery": [
        1,
        "selector"
    ],
    "no-silent": 1,
    "no-view-collection-models": 2,
    "no-view-model-attributes": 2,
    "no-view-onoff-binding": 2,
    "no-view-qualified-jquery": 0,
    "render-return": 2
}

Using specific rules

Add plugins section and specify eslint-plugin-backbone as a plugin. Enable all the rules you would like to use.

import backbone from "eslint-plugin-backbone";

export default [ {
    "plugins": {
        "backbone": backbone
    },
    "rules": {
        "backbone/collection-model": 1,
        "backbone/defaults-on-top": 1,
        "backbone/model-defaults": 1,
        "backbone/no-constructor": 1,
        "backbone/no-native-jquery": 1,
    }
} ]

If you are using custom models/view/collection bases you also have to specify each on in the settings section

import backbone from "eslint-plugin-backbone";

export default [ {
    "plugins": {
        "backbone": backbone
    },
    "rules": {
        "backbone/collection-model": 1,
        "backbone/defaults-on-top": 1,
        "backbone/model-defaults": 1,
        "backbone/no-constructor": 1,
        "backbone/no-native-jquery": 1,
    },
    "settings": {
        "backbone": {
            "Collection": ["Backbone.NestedCollection", "MyCollection"],
            "Model": ["MyBaseModel"],
            "View": ["MyBaseView"]
        }
    }
} ]

List of supported rules

About

Backbone specific linting rules for ESLint

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors