0.1.1-dev.3 • Published 1 year ago

@clap404/eslint-plugin-sql v0.1.1-dev.3

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
1 year ago

eslint-plugin-sql

This is a fork I made to support sql-formatter as a backend instead of pg-formatter. The rationale is that this way, this plugin supports more sql dialects, and there is more flexibility with the formatting.

forked from eslint-plugin-sql by @kuizinas

SQL linting rules for ESLint.

This plugin is currently alpha and untested. Do not use for anything critical !

Installation

  1. Install ESLint.
  2. Install eslint-plugin-sql plugin.
npm install eslint --save-dev
npm install @clap404/eslint-plugin-sql --save-dev

Configuration

  1. Add plugins section and specify eslint-plugin-sql as a plugin.
  2. Enable rules.
plugins:
    - '@clap404/sql'
rules:
    '@clap404/sql/format':
        - error
        - ignoreExpressions: false
          ignoreInline: true
          ignoreTagless: true
          startWithNewLine: true
          matchOuterIndentation: true
        - language: postgresql
          keywordCase: lower
          indentStyle: tabularLeft
    '@clap404/sql/no-unsafe-query':
       - error
       - allowLiteral: false

Settings

placeholderRule

A regex used to ignore placeholders or other fragments of the query that'd make it invalid SQL query, e.g.

If you are using ? placeholders in your queries, you must ignore \? pattern as otherwise the string is not going to be recognized as a valid SQL query.

This configuration is relevant for @clap404/sql/no-unsafe-query to match queries containing placeholders as well as for @clap404/sql/format when used with {ignoreTagless: false} configuration.

Rules

format

The --fix option on the command line automatically fixes problems reported by this rule.

Matches queries in template literals. Warns when query formatting does not match the configured format (see Options).

This rule is used to format the queries using sql-formatter.

Options

The first option is an object with the following configuration.

configurationformatdefaultdescription
ignoreExpressionsbooleanfalseDoes not format template literals that contain expressions.
ignoreInlinebooleantrueDoes not format queries that are written on a single line.
ignoreTaglessbooleantrueDoes not format queries that are written without using sql tag.
startWithNewLinebooleantrueAlways start a sql template on a new line.
matchOuterIndentationbooleantrueIndent the sql template from the same leven as enclosing code.
extraIndentLevelnumber1add extra indent levels to the inline sql.

The second option is an object with the sql-formatter configuration.

no-unsafe-query

Disallows use of SQL inside of template literals without the sql tag.

The sql tag can be anything, e.g.

Options

The first option is an object with the following configuration.

configurationformatdefaultdescription
allowLiteralbooleanfalseControls whether sql tag is required for template literals containing literal queries, i.e. template literals without expressions.
0.1.1-dev.1

1 year ago

0.1.1-dev.2

1 year ago

0.1.1-dev.3

1 year ago

0.0.3-1

1 year ago

0.0.4-1

1 year ago

0.1.0

1 year ago

0.0.3

1 year ago

0.0.4

1 year ago

0.0.2-alpha.1

1 year ago

0.0.1-alpha.6

1 year ago

0.0.1-alpha.5

1 year ago

0.0.1-alpha.4

1 year ago

0.0.1-alpha.3

1 year ago

0.0.1-alpha.2

1 year ago