hana-linter 1.3.0 → 1.4.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/CHANGELOG.md +6 -0
- package/dist/config.js +9 -1
- package/dist/config.test.d.ts +1 -0
- package/dist/config.test.js +55 -0
- package/package.json +1 -1
- package/src/config.test.ts +58 -0
- package/src/config.ts +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
### 1.4.0
|
|
8
|
+
|
|
9
|
+
- Bumped package version metadata to `1.4.0` (`package.json` and `package-lock.json`)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
7
13
|
### 1.3.0
|
|
8
14
|
|
|
9
15
|
- Added Chevrotain-based `.hdbtrigger` parser; content-linting of trigger names is now fully supported
|
package/dist/config.js
CHANGED
|
@@ -160,7 +160,15 @@ function isJsonLintConfig(value) {
|
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
function isContentTarget(target) {
|
|
163
|
-
return target === 'field' ||
|
|
163
|
+
return (target === 'field' ||
|
|
164
|
+
target === 'inputParameter' ||
|
|
165
|
+
target === 'outputParameter' ||
|
|
166
|
+
target === 'roleName' ||
|
|
167
|
+
target === 'grantedRoleName' ||
|
|
168
|
+
target === 'sequenceName' ||
|
|
169
|
+
target === 'jobAction' ||
|
|
170
|
+
target === 'indexName' ||
|
|
171
|
+
target === 'triggerName');
|
|
164
172
|
}
|
|
165
173
|
function compileRuleGroup(groups, contextRoot) {
|
|
166
174
|
const allRules = (groups.all ?? []).map((rule, index) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_os_1 = require("node:os");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const vitest_1 = require("vitest");
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
const supportedTargets = [
|
|
12
|
+
'field',
|
|
13
|
+
'inputParameter',
|
|
14
|
+
'outputParameter',
|
|
15
|
+
'roleName',
|
|
16
|
+
'grantedRoleName',
|
|
17
|
+
'sequenceName',
|
|
18
|
+
'jobAction',
|
|
19
|
+
'indexName',
|
|
20
|
+
'triggerName'
|
|
21
|
+
];
|
|
22
|
+
(0, vitest_1.describe)('readJsonConfig', () => {
|
|
23
|
+
(0, vitest_1.it)('accepts the bundled default configuration', async () => {
|
|
24
|
+
const configPath = node_path_1.default.resolve(process.cwd(), 'src/assets/.hana-linter.json');
|
|
25
|
+
await (0, vitest_1.expect)((0, config_1.readJsonConfig)(configPath)).resolves.toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
vitest_1.it.each(supportedTargets)('accepts content target "%s"', async (target) => {
|
|
28
|
+
const tempDir = await node_fs_1.promises.mkdtemp(node_path_1.default.join((0, node_os_1.tmpdir)(), 'hana-linter-config-'));
|
|
29
|
+
const configPath = node_path_1.default.join(tempDir, '.hana-linter.json');
|
|
30
|
+
const config = {
|
|
31
|
+
rootDir: 'db',
|
|
32
|
+
ignoredDirectories: ['node_modules'],
|
|
33
|
+
extensionRuleSets: [
|
|
34
|
+
{
|
|
35
|
+
extension: '*',
|
|
36
|
+
groups: {
|
|
37
|
+
all: [{ description: 'Any name', pattern: '.+' }]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
contentRuleSets: [
|
|
42
|
+
{
|
|
43
|
+
extension: '.hdbtable',
|
|
44
|
+
target,
|
|
45
|
+
groups: {
|
|
46
|
+
all: [{ description: 'Any name', pattern: '.+' }]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
await node_fs_1.promises.writeFile(configPath, JSON.stringify(config), 'utf-8');
|
|
52
|
+
await (0, vitest_1.expect)((0, config_1.readJsonConfig)(configPath)).resolves.toEqual(config);
|
|
53
|
+
await node_fs_1.promises.rm(tempDir, { recursive: true, force: true });
|
|
54
|
+
});
|
|
55
|
+
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { readJsonConfig } from './config';
|
|
6
|
+
import { ContentTarget, JsonLintConfig } from './types/rules';
|
|
7
|
+
|
|
8
|
+
const supportedTargets: ContentTarget[] = [
|
|
9
|
+
'field',
|
|
10
|
+
'inputParameter',
|
|
11
|
+
'outputParameter',
|
|
12
|
+
'roleName',
|
|
13
|
+
'grantedRoleName',
|
|
14
|
+
'sequenceName',
|
|
15
|
+
'jobAction',
|
|
16
|
+
'indexName',
|
|
17
|
+
'triggerName'
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
describe('readJsonConfig', () => {
|
|
21
|
+
it('accepts the bundled default configuration', async () => {
|
|
22
|
+
const configPath = path.resolve(process.cwd(), 'src/assets/.hana-linter.json');
|
|
23
|
+
await expect(readJsonConfig(configPath)).resolves.toBeDefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it.each(supportedTargets)('accepts content target "%s"', async (target) => {
|
|
27
|
+
const tempDir = await fs.mkdtemp(path.join(tmpdir(), 'hana-linter-config-'));
|
|
28
|
+
const configPath = path.join(tempDir, '.hana-linter.json');
|
|
29
|
+
|
|
30
|
+
const config: JsonLintConfig = {
|
|
31
|
+
rootDir: 'db',
|
|
32
|
+
ignoredDirectories: ['node_modules'],
|
|
33
|
+
extensionRuleSets: [
|
|
34
|
+
{
|
|
35
|
+
extension: '*',
|
|
36
|
+
groups: {
|
|
37
|
+
all: [{ description: 'Any name', pattern: '.+' }]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
contentRuleSets: [
|
|
42
|
+
{
|
|
43
|
+
extension: '.hdbtable',
|
|
44
|
+
target,
|
|
45
|
+
groups: {
|
|
46
|
+
all: [{ description: 'Any name', pattern: '.+' }]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
await fs.writeFile(configPath, JSON.stringify(config), 'utf-8');
|
|
53
|
+
|
|
54
|
+
await expect(readJsonConfig(configPath)).resolves.toEqual(config);
|
|
55
|
+
|
|
56
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
57
|
+
});
|
|
58
|
+
});
|
package/src/config.ts
CHANGED
|
@@ -230,7 +230,17 @@ function isJsonLintConfig(value: unknown): value is JsonLintConfig {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
function isContentTarget(target: unknown): target is ContentTarget {
|
|
233
|
-
return
|
|
233
|
+
return (
|
|
234
|
+
target === 'field' ||
|
|
235
|
+
target === 'inputParameter' ||
|
|
236
|
+
target === 'outputParameter' ||
|
|
237
|
+
target === 'roleName' ||
|
|
238
|
+
target === 'grantedRoleName' ||
|
|
239
|
+
target === 'sequenceName' ||
|
|
240
|
+
target === 'jobAction' ||
|
|
241
|
+
target === 'indexName' ||
|
|
242
|
+
target === 'triggerName'
|
|
243
|
+
);
|
|
234
244
|
}
|
|
235
245
|
|
|
236
246
|
function compileRuleGroup(groups: { all?: readonly JsonRuleDefinition[]; any?: readonly JsonRuleDefinition[] }, contextRoot: string): RuleGroup {
|