Skip to content
🔮Linter for any languages🔮
JavaScript Perl
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test Add test Jan 4, 2018
.eslintrc init Dec 21, 2017
.travis.yml
README.md
index.js
package.json
yarn.lock

README.md

Anylint

Linter for any languages.

TravisCI badge

Anylint is a linter created to lint anything with custom rules. You can easily write your own linters in any languages!

Install

npm install -g anylint

Usage

$ anylint foo.js

To specify rc file, use --config:

$ anylint foo.pl --config ./custom-anylintrc

.anylintrc

Anylint can be configured by .anylintrc files. .anylintrc is parsed as JSON5 format. Write settings like below and put it to the project root or your $HOME/.anylintrc.

{
  // Rules applied for all files
  "*": {
    // Key must be the path of executable
    "~/bin/lint-trailing-whitespace.sh": 2  // 2 is error
  },

  // Rules for `.js` files
  ".js": {
    "~/bin/eslint-wrapper.js": 2,
    "~/bin/jshint-wrapper.pl": 2,
  },
}

Writing Rules

Anylint accepts any rules you write. Rules must satisfy following spec:

  • Rules must be executable file (Don't forget chmod +x)
  • Rules take code to lint from stdin
  • Rules output errors in JSON format
$ cat foo.md | ./rule.pl
[{
  line: 1,
  column: 1,
  message: "Invalid indent",
  ruleId: "indent"
}, {
  line: 10,
  column: 13,
  message: "Use snake_case for variables",
  ruleId: "snake-case"
}]

Errors must have following properties:

  • line
  • column
  • message
  • ruleId

Note that line and column starts from 1, not 0.

Examples

in JavaScript:

#!/usr/bin/env node
// This rule disallows more than 2 blank lines

process.stdin.on('data', data => {
  const lines = data.toString().split('\n');
  let lastline = 'DUMMY';

  let errors = [];
  lines.forEach((line, lineNum) => {
    if (lastline.match(/^\s*$/) && line.match(/^\s*$/)) {
      errors.push({
        line: lineNum + 1,
        column: 1,
        message: 'Too many blank lines!',
        ruleId: 'no-multiple-blank-lines'
      });
    }
    lastline = line;
  });

  console.log(JSON.stringify(errors));
});

in Perl:

#!/usr/bin/env perl
# This rule disallows more than 2 blank lines
use strict;
use warnings;
use JSON;
use v5.010;

my $errors = [];

my $linenum = 1;
my $lastline = 'DUMMY';
while (<>) {
  my $line = $_;
  if ($line =~ /^\s*$/ && $lastline =~ /^\s*$/) {
    push @$errors, {
      line => $linenum,
      column => 1,
      message => 'Too many blank lines!',
      ruleId => 'no-multiple-blank-lines',
    }
  }
  $linenum++;
  $lastline = $line;
}

say encode_json($errors);

LICENSE

MIT

You can’t perform that action at this time.