Coder Social home page Coder Social logo

sparksp / elm-review-rules-to-avoid Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 519 KB

Provides some elm-analyse rules for elm-review that we don't want to publish. These are written as an exercise to confirm they're possible.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 3.15% Elm 96.85%
elm-review

elm-review-rules-to-avoid's Introduction

Hi there ๐Ÿ‘‹

elm-review-rules-to-avoid's People

Contributors

dependabot[bot] avatar sparksp avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

elm-review-rules-to-avoid's Issues

NoSingleFieldRecord

See https://stil4m.github.io/elm-analyse/#/messages/SingleFieldRecord

What the rule should do:

Forbid records and extensible records with only one field.

What problems does it solve:

Using a record is obsolete if you only plan to store a single field in it. You can use the field's type or introduce a custom Type instead.

Example of things the rule would report:

  • Records in type aliases
  • Records in function signature (argument or return)
  • Records in custom types
  • Records in records, tuples or sub-types

Example of things the rule would not report:

  • Any records with more than one field
  • Pattern matching a single field

When (not) to enable this rule:

This rule could be really handy, except for a few situational occasions when you really wouldn't want it. Including:

  • Named arguments

NoNothingToNothing

See https://stil4m.github.io/elm-analyse/#/messages/MapNothingToNothing

What the rule should do:

Forbid case expressions where Nothing is matched and then Nothing is returned.

What problems does it solve:

It makes the code more complicated than necessary. Use May.andThen or Maybe.map instead.

Example of things the rule would report:

module Greet exposing (greet)

greet : Maybe String -> Maybe String
greet maybeName =
    case maybeName of
        Nothing ->
            Nothing

        Just name ->
            Just ("Hello " ++ name)

Example of things the rule would not report:

module Greet exposing (greet)

greet : Maybe String -> Maybe String
greet maybeName =
    case maybeName of
        Nothing ->
           Just "Hello"

        Just name ->
            Just ("Hello " ++ name)

When (not) to enable this rule:

You don't need this rule. If you're writing code like this then there may be some wider code restructures to consider.

I am looking for:

  • Reasons you would / would not want to use this rule.

NoSingleFieldRecord should report records in custom types

Related #2.

Examples of things the rule should report:

type Foo
    = Foo { bar : String }

type Bish a
    = Bish { a | bosh : String }

Examples of things the rule should not report:

type Point
    = Point { x : Int, y : Int }

type Bish a
    = Bish { a | bosh : String, bash : Int }

NoFunctionInLet

See: https://stil4m.github.io/elm-analyse/#/messages/FunctionInLet

What the rule should do:

Forbid the declaration of functions in let expressions.

What problems does it solve:

In a let statement you can define variables and functions in their own scope. But you are already in the scope of a module. Just define the functions you want on a top-level. There is no not much need to define functions in let statements.

This will also stop you from mixing values into the local function from the scope (which can cause unexpected performance reductions).

Example of things the rule would report:

foo : Int -> Int
foo x =
    let
        somethingIShouldDefineOnTopLevel : Int -> Int
        somethingIShouldDefineOnTopLevel y =
            y + 1
    in
        somethingIShouldDefineOnTopLevel x

Example of things the rule would not report:

  • Anything without a function signature type annotation or an argument (where it's not clear whether it's a constant or a function).

When (not) to enable this rule:

Just don't enable this - whilst it's a good basic rule of thumb, there often needs to be much more to this review than this simple rule can account for.

I am looking for:

  • Good reasons not to use this rule.

Maintain docs.json with CI

We should use GitHub Actions to ensure that docs.json is kept up to date so that the doc preview is always correct.

NoSingleFiledRecord should report records in other records

Related #2.

Examples of things that should be reported:

type alias Vector =
    { start : { point : Point }
    , end : { point : Point }
    }

Examples of things that should not be reported:

type alias Vector =
    { start : { x : Int, y : Int }
    , end : { x : Int, y : Int }
    }

NoSingleLineRecords

See https://stil4m.github.io/elm-analyse/#/messages/MultiLineRecordFormatting

What the rule should do:

Forbid record definitions in type aliases that are written on a single line.

What problems does it solve:

Records are easier to read and give more meaningful source control diff when they're written one field per line.

Example of things the rule would report:

module Foo exposing (Person)

type alias Person =
    { name : String, age : Int, address : Address }

Example of things the rule would not report:

module Foo exposing (Person)

type alias Person =
    { name : String
    , age : Int
    , address : Address
    }

It would also ignore record definitions used in function signatures and all record construction.

When (not) to enable this rule:

You don't ever need to enable this rule. This is a code style that can easily be reviewed manually as appropriate.

I am looking for:

  • Reasons why you would want to use this rule.
  • Reasons why you would not want to use this rule.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.