Git Product home page Git Product logo

dogma's Introduction

Dogma

FOR SHAME!

Build Status Coverage Hex version Hex downloads Inline docs

This tool has been deprecated

With the new formatter in Elixir v1.6 I don't think there is a use for Dogma any more. Thanks for using this linter, it's been fun :)

Intro

Dogma is a principle or set of principles laid down by an authority as incontrovertibly true.

It's also a code style linter for Elixir, powered by shame.

About

Dogma is a tool for enforcing a consistent Elixir code style within your project, the idea being that if your code is easier to read, it should also be easier to understand. It's highly configurable so you can adjust it to fit your style guide, but comes with a sane set of defaults so for most people it should just work out-of-the-box. I like to run Dogma on the CI server with the test suite, and consider the build broken if Dogma reports a problem.

If you're interested in a tool more geared towards making style suggestions rather than strictly enforcing your style guide, check out Credo.

Usage

Add Dogma to your Mix dependencies

# mix.exs
def deps do
  [
    {:dogma, "~> 0.1", only: :dev},
  ]
end

Fetch it:

mix deps.get

Run the mix task:

mix dogma

You'll get something like this:

Inspecting 27 files.

.....X..........X..........

27 files, 2 errors!

== lib/dogma/rules.ex ==
23: TrailingBlankLines: Blank lines detected at end of file

== test/dogma/formatter_test.exs ==
9: TrailingWhitespace: Trailing whitespace detected

How handy!

Install Dogma globally

In order to run dogma from any directory build the escript:

mix escript.build

this will create an executable that you can place in your PATH and invoke from anywhere.

Contributor Information

Test it

mix test       # Run tests once
mix test.watch # Run tests on file changes
mix dogma      # Dogfooding- run the linter!

Read the developer docs

Check them out on hexdocs, or generate them yourself:

mix docs

LICENCE

Dogma - A code style linter for Elixir, powered by shame.
Copyright © 2015 Louis Pilfold - MIT Licence

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

dogma's People

Contributors

5thwall avatar alxndr avatar bozydar avatar cgiffard avatar henrik avatar jacknoble avatar joe-noh avatar jonrowe avatar kthelgason avatar lee-dohm avatar lpil avatar meadsteve avatar msoedov avatar neerfri avatar p-seebauer avatar pjambet avatar revdan avatar rranelli avatar rrrene avatar rubysolo avatar russvanbert avatar scouten-adobe avatar scripttease avatar shamil614 avatar smeevil avatar techgaun avatar thijswouters avatar timbuchwaldt avatar tolbrino avatar toupeira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dogma's Issues

Rule: Unless Not

Disallow this

unless not predicate do
  something
end

and this

unless !predicate do
  something
end

in favour of this

if predicate do
  something
end

Can share logic with IfNot (#13)

Ensure that Rule.list contains all the rules

It's easy to forget to add the rule to the list. Time for some metaprogramming. :)

Something to think about: We probably want to specify a list of rules that walk the AST only (see #15), so we'd probably want to insert this information into this list at compile time.

Rule: Comparison to boolean

Disallow these

foo   ==  false
foo   ==  true
foo   === false
foo   === true
foo   !=  false
foo   !=  true
foo   !== false
foo   !== true
true  ==  foo
true  === foo
true  !=  foo
true  !== foo
false ==  foo
false === foo
false !=  foo
false !== foo

Because they're totally pointless.

Rule: Semicolon

Expressions should not be terminated by semicolons.

x = 1;
y = 2;

Rule: TrailingWhitespace reports errors inside strings

"""
Hello, world!                   
There is whitespace here ^^^
"""

The second line is reported as an error, I don't think it should be. Rubocop has the same behaviour :(

Perhaps we should only disable it for triple quote strings """. That'd probably be easier too.

Rule: If Not

Disallow this

if not predicate do
  something
end

and this

if !predicate do
  something
end

in favour of this

unless predicate do
  something
end

protocol Enumerable not implemented for "'='"

Inspecting 257 files.

** (Protocol.UndefinedError) protocol Enumerable not implemented for "'='"
    (elixir) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) lib/enum.ex:112: Enumerable.reduce/3
    (elixir) lib/enum.ex:1274: Enum.reduce/3
    (elixir) lib/enum.ex:1040: Enum.map_reduce/3
    (elixir) lib/macro.ex:175: Macro.do_prewalk/3
    (elixir) lib/macro.ex:188: Macro.do_prewalk/3
    lib/dogma/script.ex:54: Dogma.Script.walk/2
    (elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3

Rule: Pipe bare value start

The first argument in a chain of pipes should be a bare value, not a function call with an argument.

I've worded this poorly.

Rule: Sigil Delimiters

We should pick a delimiter for sigils and stick to it unless the sigil contains that delimiter.

It feels like regexs should use /.

How do we avoid mistaking string contents for Elixir code?

There are times were we cannot get enough information from the AST alone, in which case we need to inspect the source of the script itself.

When doing this, it's easy to mistake the contents of a string for code, resulting in false positives.

For example, if we wanted to ensure that the + operator always had a space around it, this code should not register any errors

(String.graphemes("4+5") |> length) + 5

But unless we have a way of telling that it's in a string, we probably will probably get a false positive.

What about code in heredocs, or multi line strings?

defmodule Foo do
  """
  defmodule Bar do
    Uh oh, what's going on here?
  end
  """
end

Improve performance by not walking the AST multiple times

Currently we run each rule in turn on each file. The results in walking the AST multiple times. We could lump all the AST walking rules together and walk the tree once, applying them to each node in turn.

Currently no one is using this linter, and performance is not yet an issue, so I'm going to focus on rules and usability for the mean time.

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.