包详细信息

@tivac/eslint-plugin-svelte

tivac222MIT3.1.0

Svelte.js focused ESLint rules

eslint, eslintplugin, eslint-plugin, svelte

自述文件

@tivac/eslint-plugin-svelte

Installing the plugin

Install the plugin and its dependencies via npm.

$> npm install --save-dev @tivac/eslint-plugin-svelte

Using the plugin

Add one of the shared configs provided by this plugin to the extends section in your ESLint config.

{
    "extends" : [
        // Only enables the plugin, no rule config
        "plugin:@tivac/svelte/base"

        // or

        // Enables the plugin and all rules
        "plugin:@tivac/svelte/recommended"
    ]
}

Rules

  • derived-inputs-outputs, input & value names of derived() should match
  • reactive-curlies, don't add { ... } if there's only a single statement
  • reactive-destructuring, prefer destructuring for reactive reassignments
  • reactive-functions, don't define functions inside reactive statements
  • reactive-literals, don't assign literals in a reactive statement
  • store-prop-destructuring, don't access store values as $foo.bar but instead destructure them $: ({ bar } = $foo); for more granular redraws
  • stores-initial-value, always give svelte stores a default value
  • stores-no-async, don't use async/await inside svelte stores because it causes issues with the auto-unsubscribing features

更新日志

Changelog

3.1.0

Minor Changes

  • 4c16cd8: Added a new config, @tivac/svelte/base that loads just the plugin. The @tivac/svelte/recommended config now also automatically loads the plugin.

    The derived-inputs-ouputs rule should be a bit less likely to explode on bad input.

3.0.1

Patch Changes

  • 3babc1b: Corrected a misspelled rule name in @tivac/svelte/recommended.

3.0.0

Major Changes

  • 7a9bf17: stores-no-async only suggests

    BREAKING CHANGE:

    stores-no-async rule will no longer auto-fix and remove the leading async keyword, instead it will make a suggestion to that effect. The previous behavior wasn't safe because it didn't try to rewrite any await usage within the store method.

  • f6557ab: Renamed the share config to "recommended"

    This better matches the ESLint naming convention and also looks a bit more sane in the config.

    To update your ESLint config should require the following change:

    {
        "extends" : [
            "eslint:recommended",
    -        "plugin:@tivac/svelte/svelte"
    +        "plugin:@tivac/svelte/recommended"
        ]
    }
    

Minor Changes

  • e61ffd9: Added derived-inputs-outputs rule

    Checks that the input stores to a derived() have the expected names when used as values. Each value should match the local variable name of the input store, and have a `# Changelog prefix added like you would use in a svelte component.

    // Valid
    derived(a, $a => {});
    derived(a, ($a, set) => {});
    derived([a, b], ([$a, $b]) => {});
    
    // Invalid
    derived(a, value => {});
    derived(a, (foo, set) => {});
    derived([a, b], ([one, two]) => {});
    

2.2.0 (2022-03-29)

Miscellaneous Chores

2.1.0 (2022-03-29)

Features