Git Product home page Git Product logo

spicy-lint's Introduction

Linting rules for Spicy

This repository contains a Spicy integration for ast-grep(sg) and a collection of linting rules.

Quickstart

Building this package requires Node. To build ast-grep support for Spicy run

npm install

With that you can run the bundled linting rules with

# Check all files in directory.
./spicy-lint .

# Check given file(s).
./spicy-lint foo.spicy
module foo;

type X = unit {
    : b"HELLO";
    x: uint8 { print self.x; }
};
$ spicy-lint foo.spicy
note[print-in-prod]: print in non-debug code found
  ┌─ foo.spicy:5:16

5 │     x: uint8 { print self.x; }
  │     -----------^^^^^----------

  = Usually 'print' statements are used for debugging. Adding them in production
    code can introduce overhead, so it is best to either remove them, or move
    them to hooks marked '%debug'.

foo.spicy
note[use-skip]: use 'skip' for anonymous field
@@ -0,6 +0,6 @@
1 1│ module foo;
2 2│
3 3│ type X = unit {
4  │-    : b"HELLO";
  4│+    : skip  b"HELLO";
5 5│     x: uint8 { print self.x; }
6 6│ };
Note:
If a field is anonymous and not accessed via '$$' it can be declared 'skip'
so it is not stored.

foo.spicy
note[use-dd]: use $$ instead of field access
@@ -1,5 +1,5 @@
2 2│
3 3│ type X = unit {
4 4│     : b"HELLO";
5  │-    x: uint8 { print self.x; }
  5│+    x: uint8 { print $$; }
6 6│ };
Note:
Use '$$' to refer to a field in its hooks. This is more compact and requires
less changes if the field gets renamed.

Advanced usage

The linter script spicy-lint is a thin convenience wrapper around ast-grep(sg) which sets up an enviroment to run the linting rules in this repo, but with the Spicy integration in sgconfig.yml one has access to all ast-grep(sg) features, e.g., to run queries on code with sg run:

# To use the sg binary bundled in this package.
$ npm exec -- sg run -p 'foo' foo.spicy
foo.spicy:1:module foo;

# To use a `sg` binary from your system.
$ sg run -p 'foo' foo.spicy
foo.spicy:1:module foo;

See the ast-grep(sg) tooling documentation for an overview.

Contributing

If you developed rules which could be useful in general please consider opening a PR.

spicy-lint's People

Contributors

bbannier avatar dependabot[bot] avatar

Watchers

 avatar  avatar

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.