@pgsql/lint 18.1.2 → 18.2.1

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/ignore.js ADDED
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ /**
3
+ * Path exclusion for the file runner — `--ignore` / `ignore` in a config file.
4
+ *
5
+ * Most repositories that lint SQL on disk also *generate* SQL on disk
6
+ * (packaged modules, introspected schemas, codegen output), and linting
7
+ * generated output is noise. Patterns are gitignore-flavoured globs matched
8
+ * against the path relative to `cwd`:
9
+ *
10
+ * - `*` matches within a segment, `**` across segments, `?` one character.
11
+ * - A pattern with no glob character matches that path *and everything under
12
+ * it*, so `sql/` and `sql` both exclude `sql/app--1.0.0.sql`.
13
+ * - An unanchored pattern (no leading `/`) also matches at any segment
14
+ * boundary, so `generated/`, `**` patterns, and `*.gen.sql` all work.
15
+ * - A leading `/` anchors the pattern to `cwd`.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.makeIgnoreFilter = makeIgnoreFilter;
52
+ exports.applyIgnore = applyIgnore;
53
+ const path = __importStar(require("path"));
54
+ /** Turn a glob into a `RegExp` source anchored at both ends. */
55
+ function globToRegExpSource(glob) {
56
+ let out = '';
57
+ for (let i = 0; i < glob.length; i++) {
58
+ const ch = glob[i];
59
+ if (ch === '*') {
60
+ if (glob[i + 1] === '*') {
61
+ // `**/` may match zero segments, so `**/gen/**` also matches `gen/x`.
62
+ if (glob[i + 2] === '/') {
63
+ out += '(?:.*/)?';
64
+ i += 2;
65
+ }
66
+ else {
67
+ out += '.*';
68
+ i += 1;
69
+ }
70
+ }
71
+ else {
72
+ out += '[^/]*';
73
+ }
74
+ continue;
75
+ }
76
+ if (ch === '?') {
77
+ out += '[^/]';
78
+ continue;
79
+ }
80
+ out += ch.replace(/[.+^${}()|[\]\\]/g, '\\$&');
81
+ }
82
+ return out;
83
+ }
84
+ function compile(pattern) {
85
+ let p = pattern.trim().replace(/\\/g, '/');
86
+ if (!p || p.startsWith('#'))
87
+ return null;
88
+ const anchored = p.startsWith('/');
89
+ if (anchored)
90
+ p = p.slice(1);
91
+ p = p.replace(/^\.\//, '');
92
+ const dirOnly = p.endsWith('/');
93
+ if (dirOnly)
94
+ p = p.replace(/\/+$/, '');
95
+ if (!p)
96
+ return null;
97
+ // A plain path (or an explicit directory) excludes the subtree under it.
98
+ const source = /[*?]/.test(p) && !dirOnly
99
+ ? globToRegExpSource(p)
100
+ : `${globToRegExpSource(p)}(?:/.*)?`;
101
+ return { re: new RegExp(`^${source}$`), anchored };
102
+ }
103
+ /**
104
+ * Build a predicate that answers "is this file ignored?". Paths may be
105
+ * absolute or relative; both are compared as `cwd`-relative POSIX paths.
106
+ */
107
+ function makeIgnoreFilter(patterns = [], cwd = process.cwd()) {
108
+ const compiled = patterns.map(compile).filter((c) => c !== null);
109
+ if (compiled.length === 0)
110
+ return () => false;
111
+ return (file) => {
112
+ const rel = path.relative(cwd, path.resolve(cwd, file)).replace(/\\/g, '/');
113
+ // Outside cwd entirely — no relative pattern can meaningfully describe it.
114
+ if (rel.startsWith('../'))
115
+ return false;
116
+ const segments = rel.split('/');
117
+ for (const { re, anchored } of compiled) {
118
+ if (re.test(rel))
119
+ return true;
120
+ if (anchored)
121
+ continue;
122
+ // Unanchored: also try every suffix that starts at a segment boundary,
123
+ // so `generated/` matches `packages/x/generated/y.sql`.
124
+ for (let i = 1; i < segments.length; i++) {
125
+ if (re.test(segments.slice(i).join('/')))
126
+ return true;
127
+ }
128
+ }
129
+ return false;
130
+ };
131
+ }
132
+ /** Filter a list of files through {@link makeIgnoreFilter}. */
133
+ function applyIgnore(files, patterns, cwd) {
134
+ if (!patterns || patterns.length === 0)
135
+ return files;
136
+ const ignored = makeIgnoreFilter(patterns, cwd);
137
+ return files.filter((f) => !ignored(f));
138
+ }
package/index.d.ts CHANGED
@@ -10,9 +10,14 @@
10
10
  * Rules are injected as values, never discovered by npm name: build a linter
11
11
  * with `createLinter({ rules, severity })` and pass your own rules in.
12
12
  */
13
+ export type { ChangedFilesResult } from './changed';
14
+ export { changedFiles, changedSqlFiles, resolveChangedBase } from './changed';
15
+ export type { LintConfigFile, LoadedLintConfig } from './config';
16
+ export { CONFIG_FILENAMES, configDir, findConfigFile, loadLintConfig } from './config';
13
17
  export type { LintOptions } from './engine';
14
18
  export { lintDefinition, severityOf } from './engine';
15
- export { FileFinding, FileReport, filesAdapter, lintFiles, lintSource, lintSqlText, resolveSqlFiles, sqlTextAdapter, sqlTextDefinitions } from './file-runner';
19
+ export { FileFinding, FileLintOptions, FileReport, filesAdapter, lintFiles, lintSource, lintSqlText, resolveSqlFiles, sqlTextAdapter, sqlTextDefinitions } from './file-runner';
20
+ export { applyIgnore, makeIgnoreFilter } from './ignore';
16
21
  export type { CallOptions, Linter, LinterConfig } from './linter';
17
22
  export { createLinter } from './linter';
18
23
  export { parseUnit } from './parse-unit';
package/index.js CHANGED
@@ -12,7 +12,16 @@
12
12
  * with `createLinter({ rules, severity })` and pass your own rules in.
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.defineRule = exports.Suppressions = exports.DEFAULT_KEYWORDS = exports.requireQualifiedRefs = exports.noVariableConflict = exports.noSetSearchPath = exports.noDynamicSql = exports.LINT_RULES_BY_ID = exports.LINT_RULES_BY_CODE = exports.LINT_RULES = exports.parseUnit = exports.createLinter = exports.sqlTextDefinitions = exports.sqlTextAdapter = exports.resolveSqlFiles = exports.lintSqlText = exports.lintSource = exports.lintFiles = exports.filesAdapter = exports.severityOf = exports.lintDefinition = void 0;
15
+ exports.defineRule = exports.Suppressions = exports.DEFAULT_KEYWORDS = exports.requireQualifiedRefs = exports.noVariableConflict = exports.noSetSearchPath = exports.noDynamicSql = exports.LINT_RULES_BY_ID = exports.LINT_RULES_BY_CODE = exports.LINT_RULES = exports.parseUnit = exports.createLinter = exports.makeIgnoreFilter = exports.applyIgnore = exports.sqlTextDefinitions = exports.sqlTextAdapter = exports.resolveSqlFiles = exports.lintSqlText = exports.lintSource = exports.lintFiles = exports.filesAdapter = exports.severityOf = exports.lintDefinition = exports.loadLintConfig = exports.findConfigFile = exports.configDir = exports.CONFIG_FILENAMES = exports.resolveChangedBase = exports.changedSqlFiles = exports.changedFiles = void 0;
16
+ var changed_1 = require("./changed");
17
+ Object.defineProperty(exports, "changedFiles", { enumerable: true, get: function () { return changed_1.changedFiles; } });
18
+ Object.defineProperty(exports, "changedSqlFiles", { enumerable: true, get: function () { return changed_1.changedSqlFiles; } });
19
+ Object.defineProperty(exports, "resolveChangedBase", { enumerable: true, get: function () { return changed_1.resolveChangedBase; } });
20
+ var config_1 = require("./config");
21
+ Object.defineProperty(exports, "CONFIG_FILENAMES", { enumerable: true, get: function () { return config_1.CONFIG_FILENAMES; } });
22
+ Object.defineProperty(exports, "configDir", { enumerable: true, get: function () { return config_1.configDir; } });
23
+ Object.defineProperty(exports, "findConfigFile", { enumerable: true, get: function () { return config_1.findConfigFile; } });
24
+ Object.defineProperty(exports, "loadLintConfig", { enumerable: true, get: function () { return config_1.loadLintConfig; } });
16
25
  var engine_1 = require("./engine");
17
26
  Object.defineProperty(exports, "lintDefinition", { enumerable: true, get: function () { return engine_1.lintDefinition; } });
18
27
  Object.defineProperty(exports, "severityOf", { enumerable: true, get: function () { return engine_1.severityOf; } });
@@ -24,6 +33,9 @@ Object.defineProperty(exports, "lintSqlText", { enumerable: true, get: function
24
33
  Object.defineProperty(exports, "resolveSqlFiles", { enumerable: true, get: function () { return file_runner_1.resolveSqlFiles; } });
25
34
  Object.defineProperty(exports, "sqlTextAdapter", { enumerable: true, get: function () { return file_runner_1.sqlTextAdapter; } });
26
35
  Object.defineProperty(exports, "sqlTextDefinitions", { enumerable: true, get: function () { return file_runner_1.sqlTextDefinitions; } });
36
+ var ignore_1 = require("./ignore");
37
+ Object.defineProperty(exports, "applyIgnore", { enumerable: true, get: function () { return ignore_1.applyIgnore; } });
38
+ Object.defineProperty(exports, "makeIgnoreFilter", { enumerable: true, get: function () { return ignore_1.makeIgnoreFilter; } });
27
39
  var linter_1 = require("./linter");
28
40
  Object.defineProperty(exports, "createLinter", { enumerable: true, get: function () { return linter_1.createLinter; } });
29
41
  var parse_unit_1 = require("./parse-unit");
package/linter.d.ts CHANGED
@@ -19,6 +19,10 @@ export interface LinterConfig {
19
19
  severity?: SeverityMap;
20
20
  /** Suppression directive keyword(s). Defaults to `['pgsql-lint', 'safegres']`. */
21
21
  keyword?: string | string[];
22
+ /** Glob patterns excluded by the file entry points (`lintFiles`). */
23
+ ignore?: string[];
24
+ /** Directory the `ignore` patterns are relative to (default `process.cwd()`). */
25
+ cwd?: string;
22
26
  }
23
27
  /** Narrow a single call to a subset of the linter's rules. */
24
28
  export type CallOptions = Pick<LintOptions, 'rules'>;
package/linter.js CHANGED
@@ -23,6 +23,7 @@ function createLinter(config = {}) {
23
23
  const rules = config.rules ?? rules_1.LINT_RULES;
24
24
  const severity = config.severity ?? {};
25
25
  const keyword = config.keyword ?? suppressions_1.DEFAULT_KEYWORDS;
26
+ const { ignore, cwd } = config;
26
27
  const bind = (options = {}) => ({
27
28
  ruleSet: rules,
28
29
  severity,
@@ -35,7 +36,7 @@ function createLinter(config = {}) {
35
36
  keyword,
36
37
  lintDefinition: (text, language, name, options) => (0, engine_1.lintDefinition)(text, language, name, bind(options)),
37
38
  lintSqlText: (source, options) => (0, file_runner_1.lintSqlText)(source, bind(options)),
38
- lintFiles: (paths, options) => (0, file_runner_1.lintFiles)(paths, bind(options)),
39
+ lintFiles: (paths, options) => (0, file_runner_1.lintFiles)(paths, { ...bind(options), ignore, cwd }),
39
40
  lintSource: (adapter, options) => (0, file_runner_1.lintSource)(adapter, bind(options))
40
41
  };
41
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgsql/lint",
3
- "version": "18.1.2",
3
+ "version": "18.2.1",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Source-level SQL/PL/pgSQL convention linter: fully-qualified references, no search_path, no dynamic SQL, with ESLint-style inline waivers. Pure AST, no database.",
6
6
  "main": "index.js",
@@ -36,6 +36,7 @@
36
36
  "dependencies": {
37
37
  "@pgsql/traverse": "18.7.3",
38
38
  "chalk": "^4.1.0",
39
+ "git-changed": "^0.3.0",
39
40
  "libpg-query": "18.1.4",
40
41
  "minimist": "1.2.8",
41
42
  "pgsql-parser": "18.2.3"
@@ -56,5 +57,5 @@
56
57
  "search_path",
57
58
  "dynamic-sql"
58
59
  ],
59
- "gitHead": "b6105874628cc7b8517c1ebbd99e9ad6fe786976"
60
+ "gitHead": "69cdce673db035fb1ee3b529480d39fac01512ab"
60
61
  }