eslint-plugin-sql-template 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016 Uphold
3
+ Copyright (c) 2024 Uphold
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,47 +1,40 @@
1
1
  # eslint-plugin-sql-template
2
2
 
3
- ESLint plugin with rules for using the `sql` template tag from a library such as [sql-tag](https://github.com/seegno/sql-tag) on raw SQL queries.
3
+ ESLint plugin with rules for using the `sql` template tag from a library such as [sql-tag](https://github.com/ruimarinho/sql-tag) on raw SQL queries.
4
4
 
5
5
  That library escapes data provided to an SQL query statement via interpolation. This prevents, for instance, potential SQL injection attacks.
6
6
 
7
7
  This ESLint plugin helps teams enforce the usage of that tag, to avoid overlooked vulnerabilities from creeping into their codebases.
8
8
 
9
+ ## Status
10
+
11
+ [![npm version][npm-image]][npm-url]
12
+ [![build status][ci-image]][ci-url]
13
+
9
14
  ## Installation
10
15
 
11
16
  ```sh
12
- $ npm install eslint eslint-plugin-sql-template --save-dev
17
+ npm install eslint eslint-plugin-sql-template --save-dev
13
18
  ```
14
19
 
15
20
  ## Usage
16
21
 
17
- Create an `.eslint.yml` file with the following:
18
-
19
- ```yaml
20
- plugins:
21
- - sql-template
22
- ```
23
-
24
- Then, you can add the custom rules to the `.eslint.yml` file:
25
-
26
- ```yaml
27
- rules:
28
- - sql-template/no-unsafe-query: 2
29
- ```
30
-
31
- To lint your project with ESLint, add the following `script` to your `package.json`:
22
+ Add `sql-template` to both the `plugins` and `rules` sections of your `ESLint` configuration file. Example:
32
23
 
33
- ```json
34
- {
35
- "scripts": {
36
- "lint": "eslint ."
24
+ ```js
25
+ // eslint.config.js
26
+ import sqlTemplate from 'eslint-plugin-sql-template';
27
+
28
+ module.exports = [
29
+ {
30
+ plugins: {
31
+ 'sql-template': sqlTemplate
32
+ },
33
+ rules: {
34
+ 'sql-template/no-unsafe-query': 'error'
35
+ }
37
36
  }
38
- }
39
- ```
40
-
41
- and run the linter with:
42
-
43
- ```sh
44
- $ npm run lint
37
+ ];
45
38
  ```
46
39
 
47
40
  ## Rules
@@ -81,3 +74,32 @@ Users.query(`SELECT id, name FROM users`);
81
74
  const punctuation = '!';
82
75
  foo.bar(`Not SQL${punctuation}`);
83
76
  ```
77
+
78
+ ## License
79
+
80
+ [MIT](https://opensource.org/licenses/MIT)
81
+
82
+ ## Contributing
83
+
84
+ ### Development
85
+
86
+ Install dependencies:
87
+
88
+ ```sh
89
+ npm i
90
+ ```
91
+
92
+ Run tests:
93
+
94
+ ```sh
95
+ npm run test
96
+ ```
97
+
98
+ ### Cutting a release
99
+
100
+ The release process is automated via the [release](https://github.com/uphold/eslint-plugin-sql-template/actions/workflows/release.yaml) GitHub workflow. Run it by clicking the "Run workflow" button.
101
+
102
+ [npm-image]: https://img.shields.io/npm/v/eslint-plugin-sql-template.svg
103
+ [npm-url]: https://www.npmjs.com/package/eslint-plugin-sql-template
104
+ [ci-image]: https://github.com/uphold/eslint-plugin-sql-template/actions/workflows/ci.yaml/badge.svg?branch=master
105
+ [ci-url]: https://github.com/uphold/eslint-plugin-sql-template/actions/workflows/ci.yaml
package/index.js CHANGED
@@ -4,6 +4,11 @@
4
4
  * Export rules.
5
5
  */
6
6
 
7
- module.exports.rules = {
8
- 'no-unsafe-query': require('./rules/no-unsafe-query')
7
+ module.exports = {
8
+ meta: {},
9
+ configs: {},
10
+ rules: {
11
+ 'no-unsafe-query': require('./rules/no-unsafe-query')
12
+ },
13
+ processors: {}
9
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-sql-template",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "ESLint plugin with rules for using the `sql` template tag on raw SQL queries",
5
5
  "keywords": [
6
6
  "plugin",
@@ -25,15 +25,31 @@
25
25
  "sql-parse": "^0.1.5"
26
26
  },
27
27
  "engines": {
28
- "node": ">=4"
28
+ "node": ">=20"
29
+ },
30
+ "files": [
31
+ "index.js",
32
+ "rules"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
29
36
  },
30
37
  "scripts": {
31
- "changelog": "github_changelog_generator --header-label '# Changelog' --no-issues --no-verbose --future-release=$npm_config_future_release && sed -i '' -e :a -e '$d;N;2,3ba' -e 'P;D' CHANGELOG.md",
32
- "test": "mocha --recursive",
33
- "version": "npm run changelog --future-release=$npm_package_version && git add -A CHANGELOG.md"
38
+ "lint": "eslint .",
39
+ "release": "release-it",
40
+ "test": "mocha test --recursive"
34
41
  },
35
42
  "devDependencies": {
36
- "eslint": "^3.6.1",
37
- "mocha": "^3.1.0"
43
+ "@eslint/js": "^9.12.0",
44
+ "@uphold/github-changelog-generator": "^3.4.0",
45
+ "eslint": "^9.12.0",
46
+ "eslint-config-prettier": "^9.1.0",
47
+ "eslint-plugin-prettier": "^5.2.1",
48
+ "mocha": "^10.7.3",
49
+ "prettier": "^3.3.3",
50
+ "release-it": "^17.9.0"
51
+ },
52
+ "peerDependencies": {
53
+ "eslint": ">=9"
38
54
  }
39
55
  }
@@ -17,6 +17,8 @@ function isSqlQuery(literal) {
17
17
 
18
18
  try {
19
19
  parser.parse(literal);
20
+
21
+ // eslint-disable-next-line no-unused-vars
20
22
  } catch (error) {
21
23
  return false;
22
24
  }
@@ -41,7 +43,10 @@ function validate(node, context) {
41
43
  const literal = node.quasis.map(quasi => quasi.value.raw).join('x');
42
44
 
43
45
  if (isSqlQuery(literal)) {
44
- context.report(node, 'Use the `sql` tagged template literal for raw queries');
46
+ context.report({
47
+ node,
48
+ message: 'Use the `sql` tagged template literal for raw queries'
49
+ });
45
50
  }
46
51
  }
47
52
  }
@@ -50,11 +55,24 @@ function validate(node, context) {
50
55
  * Export `no-unsafe-query`.
51
56
  */
52
57
 
53
- module.exports = context => ({
54
- CallExpression(node) {
55
- node.arguments.forEach(argument => validate(argument, context));
58
+ module.exports = {
59
+ meta: {
60
+ type: 'suggestion',
61
+ docs: {
62
+ description: 'disallow unsafe SQL queries',
63
+ recommended: false,
64
+ url: 'https://github.com/uphold/eslint-plugin-sql-template#rules'
65
+ },
66
+ schema: [] // no options
56
67
  },
57
- VariableDeclaration(node) {
58
- node.declarations.forEach(declaration => validate(declaration.init, context));
68
+ create(context) {
69
+ return {
70
+ CallExpression(node) {
71
+ node.arguments.forEach(argument => validate(argument, context));
72
+ },
73
+ VariableDeclaration(node) {
74
+ node.declarations.forEach(declaration => validate(declaration.init, context));
75
+ }
76
+ };
59
77
  }
60
- });
78
+ };
package/.npmignore DELETED
@@ -1,37 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
- npm-debug.log*
5
-
6
- # Runtime data
7
- pids
8
- *.pid
9
- *.seed
10
-
11
- # Directory for instrumented libs generated by jscoverage/JSCover
12
- lib-cov
13
-
14
- # Coverage directory used by tools like istanbul
15
- coverage
16
-
17
- # nyc test coverage
18
- .nyc_output
19
-
20
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21
- .grunt
22
-
23
- # node-waf configuration
24
- .lock-wscript
25
-
26
- # Compiled binary addons (http://nodejs.org/api/addons.html)
27
- build/Release
28
-
29
- # Dependency directories
30
- node_modules
31
- jspm_packages
32
-
33
- # Optional npm cache directory
34
- .npm
35
-
36
- # Optional REPL history
37
- .node_repl_history
package/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: node_js
2
-
3
- node_js:
4
- - 4
5
- - 6
6
-
7
- sudo: false
package/CHANGELOG.md DELETED
@@ -1,10 +0,0 @@
1
- # Changelog
2
-
3
- ## [2.0.0](https://github.com/uphold/eslint-plugin-sql-template/tree/2.0.0) (2016-10-03)
4
- **Merged pull requests:**
5
-
6
- - Remove lodash dependency [\#4](https://github.com/uphold/eslint-plugin-sql-template/pull/4) ([kurayama](https://github.com/kurayama))
7
- - Use mocha --recursive flag [\#3](https://github.com/uphold/eslint-plugin-sql-template/pull/3) ([kurayama](https://github.com/kurayama))
8
- - Update README [\#2](https://github.com/uphold/eslint-plugin-sql-template/pull/2) ([kurayama](https://github.com/kurayama))
9
- - Create project with `no-unsafe-query` rule [\#1](https://github.com/uphold/eslint-plugin-sql-template/pull/1) ([rplopes](https://github.com/rplopes))
10
-
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
- const RuleTester = require('eslint').RuleTester;
8
- const rule = require('../../rules/no-unsafe-query');
9
-
10
- RuleTester.setDefaultConfig({
11
- parserOptions: {
12
- ecmaVersion: 6
13
- }
14
- });
15
-
16
- /**
17
- * Test `no-unsafe-query`.
18
- */
19
-
20
- const ruleTester = new RuleTester();
21
-
22
- ruleTester.run('no-unsafe-query', rule, {
23
- invalid: [{
24
- code: 'const column = "*"; foo.query(`SELECT ${column} FROM foobar`);',
25
- errors: [{
26
- message: 'Use the `sql` tagged template literal for raw queries'
27
- }]
28
- }, {
29
- code: 'const column = "*"; const query = `SELECT ${column} FROM foobar`; foo.query(query);',
30
- errors: [{
31
- message: 'Use the `sql` tagged template literal for raw queries'
32
- }]
33
- }, {
34
- code: 'const column = "*"; foo.query(foobar`SELECT ${column} FROM foobar`);',
35
- errors: [{
36
- message: 'Use the `sql` tagged template literal for raw queries'
37
- }]
38
- }, {
39
- code: 'const column = "*"; const query = foobar`SELECT ${column} FROM foobar`; foo.query(query);',
40
- errors: [{
41
- message: 'Use the `sql` tagged template literal for raw queries'
42
- }]
43
- }],
44
- valid: [
45
- 'const column = "*"; foo.query(sql`SELECT ${column} FROM foobar`);',
46
- 'const column = "*"; const query = sql`SELECT ${column} FROM foobar`; foo.query(query);',
47
- 'foo.query(`SELECT column FROM foobar`);',
48
- 'const query = `SELECT column FROM foobar`; foo.query(query);',
49
- 'const foo = "bar"; baz.greet(`hello ${foo}`);',
50
- 'const foo = "bar"; const baz = `hello ${foo}`; qux.greet(baz);',
51
- 'foo.greet(`hello`);',
52
- 'const foo = `bar`; baz.greet(foo);'
53
- ]
54
- });