Enforcing best practices for Effector

Overview

eslint-plugin-effector

Enforcing best practices for Effector

This plugin uses TypeScript for more precise results, but JavaScript is supported too.

Installation

First, install ESLint:

$ yarn add -D eslint

Next, install eslint-plugin-effector:

$ yarn add -D eslint-plugin-effector

Usage

Add effector to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["effector"],
  "extends": ["plugin:effector/recommended"]
}

To configure individual rules:

{
  "rules": {
    "effector/enforce-store-naming-convention": "off"
  }
}

Supported Rules

Comments
  • Add postfix convention for store naming rule

    Add postfix convention for store naming rule

    Adds a possibility to configure convention for store naming. Prefix convention will be a default. Most new files are created for testing purposes 🙂

    closes #31

    opened by ilyaryabchinski 11
  • Rule: no-watch

    Rule: no-watch

    Watch have last computation priority.

    Frequent use of the watch can lead to races that are very difficult to debug. Often, the use of the watch can be avoided (by using target, for example).

    enhancement 
    opened by binjospookie 10
  • Rule: `keep-options-order`

    Rule: `keep-options-order`

    Story

    For now, we can write sample/guard in any order:

    sample({
      target: foo, 
      fn: (bar) => Baz, 
      source: bar, 
      clock: clock
    }) 
    

    Would be nice to enforce a more convenient order E.g. source->clock->fn->target (or clock first)

    Extra stuff

    • We also need the same thing for @sergeysova patronum I guess
    enhancement 
    opened by Kelin2025 7
  • Rule: `no-forward`

    Rule: `no-forward`

    I'd like to ban forward({ from, to }) operator, and replace it with sample({ clock, target }) instead
    The reason is that sample does the same thing that forward does, but it's completely superior in terms of features I figured out that every time I write forward somewhere, after a ~hour I rewrite it to sample because OK now I need to transform my data The only problem is that forward has different execution priority rather than sample, so sometimes it might be important

    enhancement 
    opened by Kelin2025 6
  • ESLint 8

    ESLint 8

    fixes #52

    • [x] Add meta.hasSuggestions to rules
    • [x] https://github.com/typescript-eslint/typescript-eslint/issues/3738

    We are ready! Just waiting for releases:

    • typescript-eslint v5
    • eslint v8
    opened by igorkamyshev 5
  • Unexpected token '.'

    Unexpected token '.'

    Eslint stop with error

    Referenced from: /home/user/_proj/project/front/.eslintrc.js
    
    /home/user/_proj/project/front/node_modules/eslint-plugin-effector/rules/enforce-store-naming-convention/enforce-store-naming-convention.js:32
                type?.symbol?.escapedName === "Store" &&
                     ^
    
    SyntaxError: Unexpected token '.'
        at wrapSafe (internal/modules/cjs/loader.js:915:16)
        at Module._compile (internal/modules/cjs/loader.js:963:27)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
        at Module.load (internal/modules/cjs/loader.js:863:32)
        at Function.Module._load (internal/modules/cjs/loader.js:708:14)
        at Module.require (internal/modules/cjs/loader.js:887:19)
        at require (internal/modules/cjs/helpers.js:74:18)
        at Object.<anonymous> (/home/user/_proj/project/front/node_modules/eslint-plugin-effector/index.js:3:40)
        at Module._compile (internal/modules/cjs/loader.js:999:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    
        "eslint": "^7.32.0",
        "eslint-plugin-effector": "^0.2.0",
    
    bug 
    opened by SQReder 5
  • Rule: `no-call-of-derivative-events`

    Rule: `no-call-of-derivative-events`

    Some events shouldn't be called in application:

    • Effect aware events — fx.doneDota, fx.done, etc.
    • Mapped events — const newEvent = oldEvent.map(..)
    • Store aware events $store.updates
    • Events created by methods — const event = sample({ source: $store, clock, fn })

    But these events can be called:

    • const newEvent = event.prepend()
    • const { a, b } = createApi(store, {})
    enhancement 
    opened by igorkamyshev 4
  • Rule: `no-generic-names-in-reducers`

    Rule: `no-generic-names-in-reducers`

    I propose to add check to abandon names in reducer arguments like state, payload, data, result and so on. Arguments named with context should allow to effectively understand code.

    Decline:

    const $list = createStore([])
      .on(added, (state, payload) => [...state, payload])
    

    Allowed:

    const $list = createStore([])
      .on(added, (list, item) => [...list, item])
    
    enhancement need to discuss 
    opened by sergeysova 3
  • Fix debug patronum

    Fix debug patronum

    1. Fix false positives from the rule and add test case.

    Example:

    const $store = createStore(false).on(open, () => true)
    
    1. Add a more correct deletion of the line with debug and add test case (properly saving the formatting)
    // from
    import { condition, debug, delay } from 'patronum'
    
    const $store = createStore(false)
    
    const createTest = () => {
      const state = {
        equal(a, b) {
          return a === b
        }
      }
      debug($store)
      return state
    }
    
    // into
    import { condition, delay } from 'patronum'
    
    const $store = createStore(false)
    
    const createTest = () => {
      const state = {
        equal(a, b) {
          return a === b
        }
      }
      return state
    }
    
    opened by raidenmiro 2
  • Rule `prefer-map-over-sample`

    Rule `prefer-map-over-sample`

    I found such code:

    const sendEvent = sample({ clock: somethingDone, fn: (payload) => mapper(payload) })
    

    In my opinion, it should be rewritten in this way:

    const sendEvent = somethingDone.map((payload) => mapper(payload))
    
    enhancement 
    opened by igorkamyshev 2
  • no-ambiguity-target: ложные срабатывания в фабриках

    no-ambiguity-target: ложные срабатывания в фабриках

    В фабриках на effector имеются ложные срабатывания правила effector/no-ambiguity-target на guard.

    Что говорит eslint: Method 'guard' returns 'target' and assigns the result to a variable. Consider removing one of them effector/no-ambiguity-target

    Версии пакетов: effector: 21.8.12 eslint: 7.32.0 eslint-plugin-effector: 0.3.0

    Конфиг eslint:

    module.exports = {
      root: true,
      extends: [
        'plugin:effector/recommended'
      ],
      parser: '@typescript-eslint/parser',
      plugins: [
        'effector',
        '@typescript-eslint'
      ]
    }
    

    Пример кода: typescript playground

    bug good first issue 
    opened by sezyara 2
  • Improve documentation about TypeScript parser for ESLint

    Improve documentation about TypeScript parser for ESLint

    Rule effector/mandatory-scope-binding not working - no warnings/errors Example: https://stackblitz.com/edit/effector-vite-react-template-2sj3r3?file=src%2Fapplication.tsx

    documentation good first issue preset:react 
    opened by mindyourlifeguide 6
  • Rule: `no-effects-in-components`

    Rule: `no-effects-in-components`

    Using effects in components typically leads to business logic leaks into view. A cleaner approach is to use events instead of effects. I suggest to add corresponding rule to warn a user about it.

    // Fail
    function Component() {
      useUnit(someFx)
      useEvent(someFx)
      useEffect(() => {
        someFx()
        () => someFx()
      }, [])
      const callback = () => {
        someFx()
      }
      useCallback(() => {
        someFx()
      }, [])
    }
    
    enhancement 
    opened by San4es 0
  • Rule: `max-lines-per-unit`

    Rule: `max-lines-per-unit`

    Enforce a maximum number of lines of code in a unit

    Some people consider large functions a code smell. Large fn or filter in sample can make it hard to follow what’s going on. This rule should help enforce that style. It should have separate configurations for all major units (sample, guard, effect) with appropriate default values per each

    RFC 
    opened by Lonli-Lokli 1
  • Rule: `no-restore`

    Rule: `no-restore`

    Personally, I hate restore because of the following pattern 👇

    const $currency = restore(currencyInited, null).on(settingsChanges, (_, { ccurency}) => currency);
    

    Furthermore, I doubt that one line of code is a good reason to skip the full store declaration.

    enhancement good first issue preset:strict 
    opened by igorkamyshev 1
  • Rule: `no-on`

    Rule: `no-on`

    $store.on is less extendable than sample, and it could be replaced with sample. Let's add a rule to check this.

    In my mind, we should not add it to recommended preset, but it would be useful in future preset (maybe).

    enhancement good first issue preset:strict 
    opened by igorkamyshev 1
Releases(v0.10.3)
Owner
effector ☄️
Effector is an effective multi-store state manager for Javascript apps
effector ☄️
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
An IoT bottle that tracks water consumption. Winner of Best Health Hack, MLH's Best Hardware Hack, and QB3's Best Big Data for the Improvement of Health Care Winner at CruzHacks 2022.

An IoT bottle that tracks water consumption. Winner of Best Health Hack, MLH's Best Hardware Hack, and QB3's Best Big Data for the Improvement of Health Care Winner at CruzHacks 2022.

Nathanael Garza 2 Jan 21, 2022
:white_check_mark: The Node.js best practices list (March 2021)

Node.js Best Practices Follow us on Twitter! @nodepractices Read in a different language: CN, BR, RU, PL, JA, EU (ES, FR, HE, KR and TR in progress! )

Yoni Goldberg 85k Jan 9, 2023
A set of best practices for JavaScript projects

中文版 | 日本語版 | 한국어 | Русский | Português Project Guidelines · While developing a new project is like rolling on a green field for you, maintaining it is

Elsewhen 28.4k Jan 1, 2023
Best practices for modern web development

Web Fundamentals on DevSite Welcome to the new WebFundamentals! An effort to showcase best practices and tools for modern Web Development. What's chan

Google 13.7k Dec 30, 2022
An easy-to-read, quick reference for JS best practices, accepted coding standards, and links around the Web

Feel free to contribute! Where? http://www.jstherightway.org Why? Today we have a bunch of websites running JavaScript. I think we need a place to put

BrazilJS 8.5k Jan 1, 2023
Some HTML, CSS and JS best practices.

Frontend Guidelines HTML Semantics HTML5 provides us with lots of semantic elements aimed to describe precisely the content. Make sure you benefit fro

Benjamin De Cock 8.1k Jan 1, 2023
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)

?? Why this guide can take your testing skills to the next level ?? 46+ best practices: Super-comprehensive and exhaustive This is a guide for JavaScr

Yoni Goldberg 19.9k Jan 2, 2023
Mongoose Node.js Express TypeScript application boilerplate with best practices for API development.

Node TypeScript Boilerplate Mongoose The main purpose of this repository is to show a good end-to-end project setup and workflow for writing a Mongoos

Chirag Mehta 20 Dec 13, 2022
A solid create-remix app, that applies best practices into a clean, batteries included template. SQLite version. Deploys to Fly.io

Remix Barebones Stack npx create-remix --template dev-xo/barebones-stack A solid create-remix app, that follows community guidelines and applies best

Dev XO 97 Dec 30, 2022
Algorithms and Data Structures implemented in TypeScript for beginners, following best practices.

The Algorithms - TypeScript TypeScript Repository of TheAlgorithms, which implements various algorithms and data structures in TypeScript. These imple

The Algorithms 166 Dec 31, 2022
In this project, I implement a Simple To Do List with the CRUD (create, read, update, delete) methods. I followed the JavaScript, CSS, HTML, DRY, KISS and YAGNI Best practices.

To Do list: add & remove In this project, I implement a Simple To Do List with the CRUD (create, read, update, delete) methods. All the elements of th

Olivier 6 Nov 20, 2022
In this project, I built a to-do list app, which is inspired by the minimalist website. Build withHTML/CSS & JavaScript best practices: Correct use of tags, elements, properties and syntax.

Webpack Exercise In this project, I built a to-do list app, which is inspired by the minimalist website. Built With HTML/CSS & JavaScript best practic

Vanessa Oliveros 3 Oct 11, 2022
Do i follow JS best practices?

To-Do-List-code-review Do i follow JS best practices? Built With HTML CSS JavaScript ES6 Webpack Live Demo (https://kelvin-ben.github.io/To-Do-list/)

Kelvin Benjamin 3 Oct 10, 2022
for this repo I'll do some practices(exercices) using Jest for testing my javscript code.

js-testing for this repo I'll do some practices(exercices) using Jest for testing my javscript code. Here are questions for all resolved js Jest testi

Kandy Peter Kamuntu 6 Mar 16, 2022
This is a place to define better practices in code.

Better Practices Categories Angular General Programming GitHub Pages JavaScript Naming Conventions React Influence This guide is heavily influenced by

Bob Fornal 18 Sep 3, 2022
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹

TypeScript Deep Dive I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from Stack

Basarat Ali Syed 18.7k Jan 4, 2023
The best UI framework out there 🦆 In development 🚀

Noia UI Getting Started | Community | Creators | ?? Noia UI ?? in development... ?? Getting Started # First clone this repository $ git clone https://

Foton 18 Mar 10, 2022