Giter Club home page Giter Club logo

sublimelinter-contrib-makefile's Introduction

tests

About

A plugin for SublimeLinter which provides linting for Makefiles.

Installation

Use Package Control: search for a package named SublimeLinter-contrib-makefile and install it. SublimeLinter must also be installed.

Checkers

This plugin is able to detect the following mistakes. They will be visually signaled in the status bar and the left gutter.

Undefined global variable names

Correct:

FOO = 1

test:
    echo $(FOO)

Incorrect:

test:
    echo $(FOO)

Undefined target names

Correct:

clean:
    rm -rf build/*

test:
    ${MAKE} clean
    pytest .

Incorrect:

test:
    ${MAKE} clean
    pytest .

Duplicated targets

When there's 2 targets with the same name, e.g.:

test:
    pytest .

test:
    pytest .

Use of spaces instead of tabs

Any line starting with a space instead of tab is considered an error, e.g.

test1:
    pytest .  # use tab

test2:
  pytest .  # use spaces

Missing .PHONY directive

This will print missing .PHONY declaration if there's a file or directory named "test" in the same directory as the Makefile:

test:
    pytest .

Trailing spaces

Any trailing space at the end of the line, e.g.:

test:
    pytest .<SPACE><SPACE><SPACE>

Unnecessary empty lines at EOF

E.g.:

test:
    pytest .


Motivations

Why not use an existing CLI tool?

As stated in SublimeLinter/package_control_channel#134, the motivation which led me to write this plugin is because the only Makefile linter I found is https://github.com/mrtazz/checkmake, which provides a quite limited set of rules. I wanted a linter which was able to identify at least undefined variable names, undefined target names, and the use of spaces instead of tabs. I found none so I wrote my own.

Why not turn this into a generic CLI tool?

Indeed that probably makes a lot more sense. I may (or may not) do this later. :)

sublimelinter-contrib-makefile's People

Contributors

giampaolo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

sublimelinter-contrib-makefile's Issues

view.substr() is slow

Using ST find_by_selector() followed by view.substr() is quite slow. By parsing cPython's Makefile this takes around 0.250 secs:

def referenced_vars(view):
    regions = view.find_by_selector("variable.parameter.makefile")
    return [x for x in regions if view.substr(x) != "${*}"]

If I remove view.substr() it takes 0.084 secs (3x faster). In general, the bottleneck appears to be view.substr(). Using a regex instead of relying on ST's internal syntax parsing will probably be a lot faster.

Constants not recognized if start with a tab

If a constant is defined like this:

ifneq (,$(shell command -v python3.8 2> /dev/null))
	PYTHON=python3.8
else
	PYTHON=python3
endif

...it is not recognized as a constant because it starts with a tab.

Constants are not recognized if defined via eval()

Example:

git-tag-release:  ## Git-tag a new release.
	$(eval VER := $(shell grep -oP '^__version__ = "\K[^"]+' linter.py))
	git tag -a $(VER) -m `git rev-list HEAD --count`:`git rev-parse --short HEAD`
	git push --follow-tags

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.