SQL linting rules for ESLint.
In its current form, the plugin has been designed and tested to work with Postgres codebase.
eslint-plugin-sql
plugin.npm install eslint --save-dev
npm install eslint-plugin-sql --save-dev
plugins
section and specify eslint-plugin-sql
as a plugin.{
"plugins": [
"sql"
],
"rules": {
"sql/format": [
2,
{
"ignoreExpressions": false,
"ignoreInline": true,
"ignoreTagless": true
}
],
"sql/no-unsafe-query": [
2,
{
"allowLiteral": false
}
]
}
}
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 sql/no-unsafe-query
to match queries containing placeholders as well as for sql/format
when used with {ignoreTagless: false}
configuration.
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 pg-formatter.
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. |
ignoreStartWithNewLine |
boolean | true |
Does not remove \n at the beginning of queries. |
The second option is an object with the pg-formatter
configuration.
The following patterns are considered problems:
`SELECT 1`
// Options: [{"ignoreInline":false,"ignoreTagless":false}]
// Message: Format the query
// Fixed code:
// `
// SELECT
// 1
// `
`SELECT 2`
// Options: [{"ignoreInline":false,"ignoreTagless":false},{"spaces":2}]
// Message: Format the query
// Fixed code:
// `
// SELECT
// 2
// `
sql`SELECT 3`
// Options: [{"ignoreInline":false}]
// Message: Format the query
// Fixed code:
// sql`
// SELECT
// 3
// `
`SELECT ${'foo'} FROM ${'bar'}`
// Options: [{"ignoreInline":false,"ignoreTagless":false}]
// Message: Format the query
// Fixed code:
// `
// SELECT
// ${'foo'}
// FROM
// ${'bar'}
// `
The following patterns are not considered problems:
sql`SELECT 1`
// Options: [{"ignoreInline":true}]
`SELECT 2`
// Options: [{"ignoreTagless":true}]
`SELECT ${'foo'} FROM ${'bar'}`
// Options: [{"ignoreExpressions":true,"ignoreInline":false,"ignoreTagless":false}]
no-unsafe-query
Disallows use of SQL inside of template literals without the sql
tag.
The sql
tag can be anything, e.g.
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. |
The following patterns are considered problems:
`SELECT 1`
// Message: Use "sql" tag
`SELECT ${'foo'}`
// Message: Use "sql" tag
foo`SELECT ${'bar'}`
// Message: Use "sql" tag
`SELECT ?`
// Message: Use "sql" tag
The following patterns are not considered problems:
`SELECT 1`
// Options: [{"allowLiteral":true}]
sql`SELECT 1`
sql`SELECT ${'foo'}`
目录 前言 一、eslint是什么? 二、使用步骤 1.引入库 安装eslint 和 eslint-plugin-vue 2.添加配置 3.添加自动化代码修复 4.在vue.config.js中设置 总结 前言 例如:随着 随着vue3项目的使用, 提高团队的代码规范和减少code review的时间, eslint的代码校验就越来越重要了。目前的pritter对vue3的支持度不是很理想,很多v
eslint-plugin-import是什么? 该插件目的在于支持ES6以上的导入/导出语法,并防止文件路径和导入名称拼写错误的问题。 import/order是什么? 按照约定的规则对引入的模块进行排序。 import/order常用规则介绍 groups 约定引入模块顺序的集合。 选项 "builtin", "external", "internal", "unknown", "parent
使用 ESLint ESLint 详尽使用参见 官方文档 http://eslint.org/docs/user-guide/configuring 配置 ESLint 可以通过以下三种方式配置 ESLint: 使用 .eslintrc 文件(支持 JSON 和 YAML 两种语法); 在 package.json 中添加 eslintConfig 配置块; 直接在代码文件中定义。 module.
ESLint couldn't find the plugin "eslint-plugin-vue". (The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "/Users/zhangqi/Desktop".) It's likely that the pl
一、Eslint介绍 http://eslint.org/docs/user-guide/configuring ESLint由 JavaScript 红宝书 作者 Nicholas C.Zakas 编写, 2013 年发布第一个版本。 ESLint是一个以可扩展、每条规则独立的,被设计为完全可配置的lint工具,一个QA工具,用来作为静态代码检查,避免低级错误和统一代码的风格。 主要有以下特点:
eslint-plugin-vue Official ESLint plugin for Vue.js �� Documentation See the official website. ⚓ Versioning Policy This plugin is following Semantic Versioning and ESLint's Semantic Versioning Policy.
eslint-plugin-node Additional ESLint's rules for Node.js �� Install & Usage $ npm install --save-dev eslint eslint-plugin-node Requires Node.js >=8.10.0 Requires ESLint >=5.16.0 Note: It recommends a
eslint-plugin-ember An ESLint plugin that provides a set of rules for Ember applications based on commonly known good practices. ❗️ Requirements ESLint >= 6 Node.js 10.* || 12.* || >= 14 �� Usage 1. I
eslint-plugin-wxml 为 lint 微信小程序 wxml 文件而开发的 eslint 插件,可使用 eslint 来检查微信小程序项目内的 wxml 代码 当开发者使用 VSCode 或者 Webstorm 时可以得到代码错误提示,目前支持的 lint 规则如下: 1. wxml/colon-style-event-binding 强制使用:冒号隔开时间绑定 2. wxml/emp
eslint-plugin-optimize-regex Optimize regex literals Installation You'll first need to install ESLint: npm i eslint --save-dev Next, install eslint-plugin-optimize-regex: npm install eslint-plugin-opt
ESLint plugin for React Native React Native specific linting rules for ESLint. This repository is structured like (and contains code from) the excellent eslint-plugin-react. Installation Install ESLin