@clap404/eslint-plugin-sql v0.1.1-dev.3
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
- Install ESLint.
- Install
eslint-plugin-sql
plugin.
npm install eslint --save-dev
npm install @clap404/eslint-plugin-sql --save-dev
Configuration
- Add
plugins
section and specifyeslint-plugin-sql
as a plugin. - 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.
configuration | format | default | description |
---|---|---|---|
ignoreExpressions | boolean | false | Does not format template literals that contain expressions. |
ignoreInline | boolean | true | Does not format queries that are written on a single line. |
ignoreTagless | boolean | true | Does not format queries that are written without using sql tag. |
startWithNewLine | boolean | true | Always start a sql template on a new line. |
matchOuterIndentation | boolean | true | Indent the sql template from the same leven as enclosing code. |
extraIndentLevel | number | 1 | add 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.
configuration | format | default | description |
---|---|---|---|
allowLiteral | boolean | false | Controls whether sql tag is required for template literals containing literal queries, i.e. template literals without expressions. |
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago