sim-node-lib 0.4.13 → 0.4.15
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/dist/Eslint/index.d.ts +1 -7
- package/dist/Eslint/index.js +40 -44
- package/dist/Eslint/plugin/rules/ensure-active-middlewares.d.ts +16 -0
- package/dist/Eslint/plugin/rules/ensure-active-middlewares.js +31 -0
- package/dist/Eslint/plugin/rules/ensure-bindings.d.ts +11 -0
- package/dist/Eslint/plugin/rules/ensure-bindings.js +5 -2
- package/dist/Eslint/plugin/rules/use-pubsub-v2.d.ts +22 -0
- package/dist/Eslint/plugin/rules/use-pubsub-v2.js +49 -0
- package/dist/Eslint/plugin/sim-eslint.d.ts +52 -5
- package/dist/Eslint/plugin/sim-eslint.js +15 -7
- package/dist/Helpers/ExceptionHelper.d.ts +3 -0
- package/dist/Helpers/ExceptionHelper.js +21 -0
- package/package.json +3 -1
- package/dist/Eslint/plugin/rules/pub-sub.d.ts +0 -2
- package/dist/Eslint/plugin/rules/pub-sub.js +0 -37
package/dist/Eslint/index.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
declare const eslintPluginPrettierRecommended: any;
|
|
3
|
-
declare const FlatCompat: any;
|
|
4
|
-
declare const compat: any;
|
|
5
|
-
declare function basic(dirname: string): any[];
|
|
6
|
-
declare function recommendedBasic(dirname: string): any[];
|
|
7
|
-
declare function recommendedTypeChecked(dirname: string): any[];
|
|
1
|
+
export {};
|
package/dist/Eslint/index.js
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 sim_eslint_1 = require("./plugin/sim-eslint");
|
|
7
|
+
const recommended_1 = __importDefault(require("eslint-plugin-prettier/recommended"));
|
|
3
8
|
const { FlatCompat } = require('@eslint/eslintrc');
|
|
4
9
|
const compat = new FlatCompat({ resolvePluginsRelativeTo: __dirname });
|
|
10
|
+
const simRules = [
|
|
11
|
+
{
|
|
12
|
+
files: ['**/*.ts'],
|
|
13
|
+
ignores: ['/database/**/*.ts'],
|
|
14
|
+
languageOptions: {
|
|
15
|
+
sourceType: 'module',
|
|
16
|
+
ecmaVersion: 'latest',
|
|
17
|
+
},
|
|
18
|
+
plugins: { 'sim-eslint': sim_eslint_1.simEslint },
|
|
19
|
+
rules: {
|
|
20
|
+
'sim-eslint/ensure-bindings': 'error',
|
|
21
|
+
'sim-eslint/use-pubsub-v2': 'error',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
files: ['start/routes/**/*.ts'],
|
|
26
|
+
ignores: ['/database/**/*.ts'],
|
|
27
|
+
languageOptions: {
|
|
28
|
+
sourceType: 'module',
|
|
29
|
+
ecmaVersion: 'latest',
|
|
30
|
+
},
|
|
31
|
+
plugins: { 'sim-eslint': sim_eslint_1.simEslint },
|
|
32
|
+
rules: {
|
|
33
|
+
'sim-eslint/ensure-active-middlewares': 'error',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
];
|
|
5
37
|
function basic(dirname) {
|
|
6
38
|
return [
|
|
7
39
|
...compat.config({
|
|
@@ -13,20 +45,8 @@ function basic(dirname) {
|
|
|
13
45
|
},
|
|
14
46
|
ignorePatterns: ['database/**', 'build/**'],
|
|
15
47
|
}),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ignores: ['/database/**/*.ts'],
|
|
19
|
-
languageOptions: {
|
|
20
|
-
sourceType: 'module',
|
|
21
|
-
ecmaVersion: 'latest',
|
|
22
|
-
},
|
|
23
|
-
plugins: { 'sim-eslint': simEslint },
|
|
24
|
-
rules: {
|
|
25
|
-
'sim-eslint/ensure-bindings': 'error',
|
|
26
|
-
'sim-eslint/pub-sub': 'error'
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
eslintPluginPrettierRecommended,
|
|
48
|
+
...simRules,
|
|
49
|
+
recommended_1.default,
|
|
30
50
|
];
|
|
31
51
|
}
|
|
32
52
|
function recommendedBasic(dirname) {
|
|
@@ -41,20 +61,8 @@ function recommendedBasic(dirname) {
|
|
|
41
61
|
},
|
|
42
62
|
ignorePatterns: ['database/**', 'build/**'],
|
|
43
63
|
}),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
ignores: ['/database/**/*.ts'],
|
|
47
|
-
languageOptions: {
|
|
48
|
-
sourceType: 'module',
|
|
49
|
-
ecmaVersion: 'latest',
|
|
50
|
-
},
|
|
51
|
-
plugins: { 'sim-eslint': simEslint },
|
|
52
|
-
rules: {
|
|
53
|
-
'sim-eslint/ensure-bindings': 'error',
|
|
54
|
-
'sim-eslint/pub-sub': 'error'
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
eslintPluginPrettierRecommended,
|
|
64
|
+
...simRules,
|
|
65
|
+
recommended_1.default,
|
|
58
66
|
];
|
|
59
67
|
}
|
|
60
68
|
function recommendedTypeChecked(dirname) {
|
|
@@ -69,20 +77,8 @@ function recommendedTypeChecked(dirname) {
|
|
|
69
77
|
},
|
|
70
78
|
ignorePatterns: ['database/**', 'build/**'],
|
|
71
79
|
}),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
ignores: ['/database/**/*.ts'],
|
|
75
|
-
languageOptions: {
|
|
76
|
-
sourceType: 'module',
|
|
77
|
-
ecmaVersion: 'latest',
|
|
78
|
-
},
|
|
79
|
-
plugins: { 'sim-eslint': simEslint },
|
|
80
|
-
rules: {
|
|
81
|
-
'sim-eslint/ensure-bindings': 'error',
|
|
82
|
-
'sim-eslint/pub-sub': 'error'
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
eslintPluginPrettierRecommended,
|
|
80
|
+
...simRules,
|
|
81
|
+
recommended_1.default,
|
|
86
82
|
];
|
|
87
83
|
}
|
|
88
84
|
module.exports.basic = basic;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const ensureActiveMiddlewares: {
|
|
2
|
+
defaultOptions: never[];
|
|
3
|
+
meta: {
|
|
4
|
+
type: string;
|
|
5
|
+
docs: {
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
messages: {
|
|
9
|
+
'ensure-active-middlewares': string;
|
|
10
|
+
};
|
|
11
|
+
schema: never[];
|
|
12
|
+
};
|
|
13
|
+
create: (context: any) => {
|
|
14
|
+
Program: () => void;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureActiveMiddlewares = void 0;
|
|
4
|
+
exports.ensureActiveMiddlewares = {
|
|
5
|
+
defaultOptions: [],
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'problem',
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Enforce not letting commented middlewares in route files.',
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
'ensure-active-middlewares': 'Do not leave commented middleware calls in route files.',
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
},
|
|
16
|
+
create: function (context) {
|
|
17
|
+
return {
|
|
18
|
+
Program: () => {
|
|
19
|
+
const comments = context.sourceCode.getAllComments();
|
|
20
|
+
for (const comment of comments) {
|
|
21
|
+
const commentText = comment.value.trim();
|
|
22
|
+
if (commentText.includes('middleware'))
|
|
23
|
+
context.report({
|
|
24
|
+
loc: comment.loc,
|
|
25
|
+
messageId: 'ensure-active-middlewares',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureBindingsRule = void 0;
|
|
4
|
+
exports.ensureBindingsRule = {
|
|
2
5
|
meta: {
|
|
3
6
|
type: 'problem',
|
|
4
7
|
docs: {
|
|
5
|
-
description: 'Enforce passing both query and bindings parameters to whereRaw()
|
|
8
|
+
description: 'Enforce passing both query and bindings parameters to whereRaw(), rawQuery() or other raw DB methods',
|
|
6
9
|
},
|
|
7
10
|
},
|
|
8
11
|
create: function (context) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types/dist';
|
|
2
|
+
export declare const usePubSubV2Rule: {
|
|
3
|
+
defaultOptions: never[];
|
|
4
|
+
meta: {
|
|
5
|
+
type: string;
|
|
6
|
+
docs: {
|
|
7
|
+
description: string;
|
|
8
|
+
url: string;
|
|
9
|
+
};
|
|
10
|
+
messages: {
|
|
11
|
+
'use-pubsub-v2': string;
|
|
12
|
+
};
|
|
13
|
+
schema: never[];
|
|
14
|
+
};
|
|
15
|
+
create: (context: any) => {
|
|
16
|
+
CallExpression?: undefined;
|
|
17
|
+
Program?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
CallExpression: (node: TSESTree.CallExpression) => void;
|
|
20
|
+
Program: () => void;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePubSubV2Rule = void 0;
|
|
4
|
+
exports.usePubSubV2Rule = {
|
|
5
|
+
defaultOptions: [],
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'problem',
|
|
8
|
+
docs: {
|
|
9
|
+
description: "Enforce using our lib's V2 PubSub version on API",
|
|
10
|
+
url: 'https://simlabs.atlassian.net/wiki/x/BwDyEQ',
|
|
11
|
+
},
|
|
12
|
+
messages: {
|
|
13
|
+
'use-pubsub-v2': "Missing our lib's PubSub V2 implementation.",
|
|
14
|
+
},
|
|
15
|
+
schema: [],
|
|
16
|
+
},
|
|
17
|
+
create: function (context) {
|
|
18
|
+
const curFilename = context.getFilename();
|
|
19
|
+
const appProvider = 'AppProvider.ts';
|
|
20
|
+
const isAppProvider = curFilename.includes(appProvider);
|
|
21
|
+
if (!isAppProvider) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
CallExpression: (node) => {
|
|
26
|
+
const { callee } = node;
|
|
27
|
+
if (callee.type === 'MemberExpression' &&
|
|
28
|
+
callee.property.type === 'Identifier' &&
|
|
29
|
+
callee.property.name === 'listenMessages') {
|
|
30
|
+
context.report({
|
|
31
|
+
node,
|
|
32
|
+
messageId: 'use-pubsub-v2',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
Program: () => {
|
|
37
|
+
const comments = context.sourceCode.getAllComments();
|
|
38
|
+
for (const comment of comments) {
|
|
39
|
+
const commentText = comment.value.trim();
|
|
40
|
+
if (commentText.includes('listenMessages') || commentText.includes('listenMessagesV2'))
|
|
41
|
+
context.report({
|
|
42
|
+
loc: comment.loc,
|
|
43
|
+
messageId: 'use-pubsub-v2',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -1,12 +1,59 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
declare const pubSubRule: any;
|
|
3
|
-
declare const plugin: {
|
|
1
|
+
export declare const simEslint: {
|
|
4
2
|
meta: {
|
|
5
3
|
name: string;
|
|
6
4
|
version: string;
|
|
7
5
|
};
|
|
8
6
|
rules: {
|
|
9
|
-
'ensure-
|
|
10
|
-
|
|
7
|
+
'ensure-active-middlewares': {
|
|
8
|
+
defaultOptions: never[];
|
|
9
|
+
meta: {
|
|
10
|
+
type: string;
|
|
11
|
+
docs: {
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
messages: {
|
|
15
|
+
'ensure-active-middlewares': string;
|
|
16
|
+
};
|
|
17
|
+
schema: never[];
|
|
18
|
+
};
|
|
19
|
+
create: (context: any) => {
|
|
20
|
+
Program: () => void;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
'ensure-bindings': {
|
|
24
|
+
meta: {
|
|
25
|
+
type: string;
|
|
26
|
+
docs: {
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
create: (context: any) => {
|
|
31
|
+
CallExpression(node: any): void;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
'use-pubsub-v2': {
|
|
35
|
+
defaultOptions: never[];
|
|
36
|
+
meta: {
|
|
37
|
+
type: string;
|
|
38
|
+
docs: {
|
|
39
|
+
description: string;
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
messages: {
|
|
43
|
+
'use-pubsub-v2': string;
|
|
44
|
+
};
|
|
45
|
+
schema: never[];
|
|
46
|
+
};
|
|
47
|
+
create: (context: any) => {
|
|
48
|
+
CallExpression?: undefined;
|
|
49
|
+
Program?: undefined;
|
|
50
|
+
} | {
|
|
51
|
+
CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
|
|
52
|
+
Program: () => void;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
languageOptions: {
|
|
57
|
+
parser: string;
|
|
11
58
|
};
|
|
12
59
|
};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simEslint = void 0;
|
|
4
|
+
const ensure_bindings_1 = require("./rules/ensure-bindings");
|
|
5
|
+
const use_pubsub_v2_1 = require("./rules/use-pubsub-v2");
|
|
6
|
+
const ensure_active_middlewares_1 = require("./rules/ensure-active-middlewares");
|
|
7
|
+
const typescriptParser = require.resolve('@typescript-eslint/parser');
|
|
8
|
+
exports.simEslint = {
|
|
9
|
+
meta: { name: 'sim-eslint', version: '1.0.2' },
|
|
5
10
|
rules: {
|
|
6
|
-
'ensure-
|
|
7
|
-
'
|
|
11
|
+
'ensure-active-middlewares': ensure_active_middlewares_1.ensureActiveMiddlewares,
|
|
12
|
+
'ensure-bindings': ensure_bindings_1.ensureBindingsRule,
|
|
13
|
+
'use-pubsub-v2': use_pubsub_v2_1.usePubSubV2Rule,
|
|
14
|
+
},
|
|
15
|
+
languageOptions: {
|
|
16
|
+
parser: typescriptParser,
|
|
8
17
|
},
|
|
9
18
|
};
|
|
10
|
-
module.exports = plugin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ExceptionHelper {
|
|
4
|
+
static findMessage(obj) {
|
|
5
|
+
for (const key in obj) {
|
|
6
|
+
if (obj.hasOwnProperty(key)) {
|
|
7
|
+
if (key === 'message') {
|
|
8
|
+
return obj[key];
|
|
9
|
+
}
|
|
10
|
+
else if (typeof obj[key] === 'object') {
|
|
11
|
+
const nestedResult = ExceptionHelper.findMessage(obj[key]);
|
|
12
|
+
if (nestedResult !== undefined) {
|
|
13
|
+
return nestedResult;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return 'Não foi encontrada uma mensagem nesse objeto.';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = ExceptionHelper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sim-node-lib",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"description": "Library from SIMLabs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,11 +31,13 @@
|
|
|
31
31
|
"@adonisjs/mrm-preset": "^5.0.3",
|
|
32
32
|
"@adonisjs/require-ts": "^2.0.13",
|
|
33
33
|
"@eslint/eslintrc": "^2.1.4",
|
|
34
|
+
"@types/eslint": "^8.56.2",
|
|
34
35
|
"@types/node": "^17.0.41",
|
|
35
36
|
"@types/pino-std-serializers": "^4.0.0",
|
|
36
37
|
"@types/uuid": "^9.0.2",
|
|
37
38
|
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
38
39
|
"@typescript-eslint/parser": "^6.17.0",
|
|
40
|
+
"@typescript-eslint/types": "^6.21.0",
|
|
39
41
|
"eslint": "^8.56.0",
|
|
40
42
|
"eslint-config-prettier": "^8.5.0",
|
|
41
43
|
"eslint-plugin-prettier": "^5.1.2",
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
let existsPubSubV2 = false;
|
|
2
|
-
let auxAppProvider = false;
|
|
3
|
-
module.exports = {
|
|
4
|
-
meta: {
|
|
5
|
-
type: 'problem',
|
|
6
|
-
docs: {
|
|
7
|
-
description: 'Enforce the use of the v2 of pubsub',
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
create: function (context) {
|
|
11
|
-
const curFilename = context.getFilename();
|
|
12
|
-
const appProvider = 'AppProvider.ts';
|
|
13
|
-
const isAppProvider = curFilename.includes(appProvider);
|
|
14
|
-
return {
|
|
15
|
-
CallExpression(node) {
|
|
16
|
-
const callee = node.callee;
|
|
17
|
-
if (isAppProvider) {
|
|
18
|
-
auxAppProvider = true;
|
|
19
|
-
if (callee.type === 'MemberExpression' && callee.property.type === 'Identifier' && callee.property.name === 'listenMessagesV2') {
|
|
20
|
-
existsPubSubV2 = true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
if (auxAppProvider) {
|
|
25
|
-
auxAppProvider = false;
|
|
26
|
-
if (!existsPubSubV2) {
|
|
27
|
-
context.report({
|
|
28
|
-
node,
|
|
29
|
-
message: '"AppProvider.ts" must contain the v2 of pubsub.',
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
};
|