npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sqlint

v1.7.1

Published

Lint tool for SQL

Downloads

7,507

Readme

SQLint

Lint tool for SQL

sqlint

Installation and Usage

You can install SQLint using npm:

$ npm install sqlint --save-dev

Or using yarn:

$ yarn add sqlint -D

Editor Support

You can use sql-language-server to use SQLint on your editor.

sqlint-on-editor

CLI

Example

$ sqlint .
Options:

Options:
  --version     Show version number                                    [boolean]
  -h            Show help                                              [boolean]
  --config, -c  Configuration file path                                 [string]
  --output, -o  Specify file to write report to                         [string]
  --format, -f  Select a output format
                      [string] [choices: "stylish", "json"] [default: "stylish"]
  --stdin       Lint code provide on <STDIN>          [boolean] [default: false]
  --fix         Automatically fix problems            [boolean] [default: false]

Use stdin example:

$ cat ./test/cli/fixtures/lint/errorSql.sql | sqlint --stdin

Fixing problems

--fix option will work to try to fix as many problems as possible.

example:

$ sqlint --fix .

Configuration

Example

{
  "rules": {
    "align-column-to-the-first": "error",
    "column-new-line": "error",
    "linebreak-after-clause-keyword": "error",
    "reserved-word-case": ["error", "upper"],
    "space-surrounding-operators": "error",
    "where-clause-new-line": "error",
    "align-where-clause-to-the-first": "error",
  }
}

Personal config file and project config file

Personal confuguration file

Personal configuration file is located on ~/.config/sql-language-server/.sqlintrc.json. It'll be applied when it can't find a project configuration file.

Project confuguration file

Project configuration file is located on ${YOUR_PROJECT_ROOT}/.sqlintrc.json.

Rule Configuration

Rule shoud be set the ruleID and one of these values:

  • "off" or 0
  • "warn" or 1
  • "error" or 2

Some rules have option that you can modify checking behaviour. For kind of those rules, you can set Array value that the first element is error level and the second element is option value.

"rule-id": ["error", "option"]

Option value's type depends on each rules. Please check each rules description to set it.

Rules

We're always finding new rules to add. If you have any prefer rules you want feel free to open a issue to discuss.

align-column-to-the-first

Align all columns to the first column on their own line.

Good

SELECT
  foo.a,
  foo.b
FROM
  foo

Bad

SELECT
  foo.a,
    foo.b
FROM
  foo
column-new-line

Columns must go on a new line.

Good

SELECT
  foo.a,
  foo.b
FROM
  foo

Bad

SELECT
  foo.a, foo.b
FROM
  foo
linebreak-after-clause-keyword

Require linebreak after SELECT, FROM, WHERE keyword.

Good

SELECT
  foo.aj
FROM
  foo
WHERE
  foo.a > 1

Bad

SELECT foo.aj
FROM foo
WHERE foo.a > 1
reserved-word-case

Reserved word's case should be unified by upper or lower.

Option: "upper" | "lower" (default: "upper")

Good

SELECT * FROM foo

Bad

select * FROM foo
space-surrounding-operators

Spaces around operators.

Option: "always" | "never" (default: "always")

Good("always")

SELECT *
FROM foo
WHERE foo.a > 1
   OR foo.b >= 2
  AND foo.c = true
   OR foo.d <> false

Good("never")

SELECT *
FROM foo
WHERE foo.a>1
   OR foo.b>=2
  AND foo.c=true
   OR foo.d<>false

Bad

SELECT *
FROM foo
WHERE foo.a > 1
   OR foo.b>=2
  AND foo.c=true
   OR foo.d <> false
where-clause-new-line

Multiple where clause must go on a new line.

Good

SELECT foo.a, foo.b
FROM foo
WHERE
  foo.a = 'a'
  AND foo.b = 'b'

Bad

SELECT foo.a, foo.b
FROM foo
WHERE
  foo.a = 'a' AND foo.b = 'b'
align-where-clause-to-the-first

Where clauses must align to the first clause.

Good

SELECT foo.a
FROM foo 
WHERE foo.a = 'a' AND foo.b = 'b' AND
      foo.c = 'c' AND
      foo.d = 'd'

Bad

SELECT foo.a
FROM foo 
WHERE foo.a = 'a' AND foo.b = 'b' AND
foo.c = 'c' AND
foo.d = 'd'
align-where-clause-to-the-first

Where clauses must align to the first clause.

Good

SELECT foo.a
FROM foo 
WHERE foo.a = 'a' AND foo.b = 'b' AND
      foo.c = 'c' AND
      foo.d = 'd'

Bad

SELECT foo.a
FROM foo 
WHERE foo.a = 'a' AND foo.b = 'b' AND
foo.c = 'c' AND
foo.d = 'd'
require-as-to-rename-column

As is always required to rename a column name.

Good

SELECT
  employees.name AS employee_name,
  COUNT(tasks.id) AS assigned_task_count
FROM
  employees LEFT JOIN tasks
    ON employees.id = tasks.id

Bad

SELECT
  employees.name employee_name,
  COUNT(tasks.id) assigned_task_count
FROM
  employees LEFT JOIN tasks
    ON employees.id = tasks.id