x-fidelity 1.6.1 → 1.8.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 +14 -0
- package/README.md +236 -148
- package/dist/archetypes/index.js +42 -57
- package/dist/archetypes/java-microservice.json +44 -0
- package/dist/archetypes/node-fullstack.json +41 -0
- package/dist/core/cli.js +2 -2
- package/dist/core/engine.js +22 -14
- package/dist/facts/repoDependencyFacts.js +5 -1
- package/dist/index.js +3 -3
- package/dist/operators/nonStandardDirectoryStructure.js +1 -1
- package/dist/server/configServer.js +39 -18
- package/dist/utils/config.js +13 -16
- package/dist/xfidelity +3 -3
- package/package.json +2 -2
- package/src/archetypes/index.ts +16 -57
- package/src/archetypes/java-microservice.json +44 -0
- package/src/archetypes/node-fullstack.json +41 -0
- package/src/core/cli.ts +2 -2
- package/src/core/engine.ts +30 -24
- package/src/facts/repoDependencyFacts.ts +5 -1
- package/src/index.ts +3 -3
- package/src/operators/nonStandardDirectoryStructure.ts +1 -1
- package/src/server/configServer.ts +35 -16
- package/src/utils/config.ts +12 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.8.0](https://github.com/zotoio/x-fidelity/compare/v1.7.0...v1.8.0) (2024-08-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Add system architecture diagram to README.md ([ce80b79](https://github.com/zotoio/x-fidelity/commit/ce80b795031c366b232e51c0cf0e651fa77c364c))
|
|
7
|
+
|
|
8
|
+
# [1.7.0](https://github.com/zotoio/x-fidelity/compare/v1.6.1...v1.7.0) (2024-07-30)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **extensibility:** archtypes as replacable json files and docs ([ce7b06d](https://github.com/zotoio/x-fidelity/commit/ce7b06df4b3ae76c4d5094b478e7425579b585b2))
|
|
14
|
+
|
|
1
15
|
## [1.6.1](https://github.com/zotoio/x-fidelity/compare/v1.6.0...v1.6.1) (2024-07-27)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# x-fidelity
|
|
2
2
|
|
|
3
|
-
x-fidelity is an advanced CLI tool designed to
|
|
3
|
+
x-fidelity is an advanced CLI tool and paired config server designed to perform opinionated framework adherence checks within a codebase. It provides a flexible and extensible way to ensure your projects are using specific standards, tools and best practices.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
=====================================
|
|
@@ -38,29 +38,32 @@ x-fidelity is an advanced CLI tool designed to enforce opinionated framework adh
|
|
|
38
38
|
|
|
39
39
|
1. [Intent and Purpose](#intent-and-purpose)
|
|
40
40
|
2. [Key Features](#key-features)
|
|
41
|
-
3. [
|
|
42
|
-
4. [
|
|
43
|
-
5. [
|
|
44
|
-
6. [
|
|
45
|
-
7. [
|
|
46
|
-
8. [
|
|
47
|
-
9. [
|
|
48
|
-
10. [
|
|
49
|
-
11. [
|
|
50
|
-
12. [
|
|
41
|
+
3. [System Architecture](#system-architecture)
|
|
42
|
+
4. [Installation](#installation)
|
|
43
|
+
5. [Usage](#usage)
|
|
44
|
+
6. [Configuration](#configuration)
|
|
45
|
+
7. [Extending x-fidelity](#extending-x-fidelity)
|
|
46
|
+
8. [OpenAI Integration](#openai-integration)
|
|
47
|
+
9. [Hosting Config Servers](#hosting-config-servers)
|
|
48
|
+
10. [Best Practices](#best-practices)
|
|
49
|
+
11. [Linting](#linting)
|
|
50
|
+
12. [Contributing](#contributing)
|
|
51
|
+
13. [License](#license)
|
|
51
52
|
|
|
52
53
|
## Intent and Purpose
|
|
53
54
|
|
|
54
55
|
x-fidelity aims to streamline the process of maintaining code quality and consistency across projects. By providing a flexible, rule-based system, it allows teams to:
|
|
55
56
|
|
|
56
|
-
- Enforce coding standards and best practices
|
|
57
|
-
- Ensure consistent project structures
|
|
58
|
-
- Maintain up-to-date dependencies
|
|
57
|
+
- Enforce bespoke coding standards and best practices
|
|
58
|
+
- Ensure consistent project archetype structures
|
|
59
|
+
- Maintain up-to-date private dependencies
|
|
59
60
|
- Catch potential issues early in the development process
|
|
60
|
-
- Integrate advanced code analysis
|
|
61
|
+
- Integrate GenAI-based advanced code analysis (experimental)
|
|
61
62
|
|
|
62
63
|
The tool is designed to be highly customizable, allowing teams to define their own archetypes, rules, and checks tailored to their specific needs and tech stacks.
|
|
63
64
|
|
|
65
|
+
> x-fidelity is not a replacement for standard linting more generalised code analysis tools. it is intended to help with management of bespoke requirements and as a simple way to experiment with GenAI based code reviews.
|
|
66
|
+
|
|
64
67
|
## Key Features
|
|
65
68
|
|
|
66
69
|
- **Flexible Archetype System**: Define custom project archetypes with specific rules and configurations.
|
|
@@ -72,6 +75,69 @@ The tool is designed to be highly customizable, allowing teams to define their o
|
|
|
72
75
|
- **OpenAI Integration**: Leverage AI for advanced code analysis and suggestions.
|
|
73
76
|
- **Extensible Architecture**: Easily add new operators, facts, and rules to suit your needs.
|
|
74
77
|
|
|
78
|
+
## System Architecture
|
|
79
|
+
|
|
80
|
+
The following diagram illustrates the overall architecture of the x-fidelity system:
|
|
81
|
+
|
|
82
|
+
```mermaid
|
|
83
|
+
graph TD
|
|
84
|
+
subgraph "Client Environments"
|
|
85
|
+
CI[CI Environment]
|
|
86
|
+
Local[Local Development]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
subgraph "x-fidelity Core"
|
|
90
|
+
Engine[Analysis Engine]
|
|
91
|
+
CLI[CLI Interface]
|
|
92
|
+
ConfigMgr[Config Manager]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
subgraph "x-fidelity Infrastructure"
|
|
96
|
+
CS[Config Server]
|
|
97
|
+
TS[Telemetry Server]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
subgraph "External Services"
|
|
101
|
+
GH[GitHub]
|
|
102
|
+
OAI[OpenAI API]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
subgraph "Data Sources"
|
|
106
|
+
Files[Repository Files]
|
|
107
|
+
Deps[Dependencies]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
CI -->|Use| Engine
|
|
111
|
+
Local -->|Use| Engine
|
|
112
|
+
CI -->|Use| CLI
|
|
113
|
+
Local -->|Use| CLI
|
|
114
|
+
|
|
115
|
+
CLI -->|Initialize| ConfigMgr
|
|
116
|
+
Engine -->|Use| ConfigMgr
|
|
117
|
+
|
|
118
|
+
ConfigMgr -->|Fetch config| CS
|
|
119
|
+
Engine -->|Send telemetry| TS
|
|
120
|
+
|
|
121
|
+
Engine -->|Analyze| Files
|
|
122
|
+
Engine -->|Check| Deps
|
|
123
|
+
|
|
124
|
+
CS -->|Optional: Fetch rules| GH
|
|
125
|
+
TS -->|Optional: Store data| GH
|
|
126
|
+
|
|
127
|
+
Engine -.->|Optional: AI analysis| OAI
|
|
128
|
+
|
|
129
|
+
classDef optional stroke-dasharray: 5 5
|
|
130
|
+
class OAI optional
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
This diagram shows the main components of x-fidelity and how they interact:
|
|
134
|
+
|
|
135
|
+
- **Client Environments**: Where x-fidelity is used (CI systems or local development).
|
|
136
|
+
- **x-fidelity Core**: The main components of the system, including the analysis engine, CLI interface, and configuration manager.
|
|
137
|
+
- **x-fidelity Infrastructure**: Servers for configuration and telemetry.
|
|
138
|
+
- **External Services**: GitHub for repository interaction and optional OpenAI integration.
|
|
139
|
+
- **Data Sources**: The files and dependencies that x-fidelity analyzes.
|
|
140
|
+
|
|
75
141
|
## Installation
|
|
76
142
|
|
|
77
143
|
Install x-fidelity using Node.js 18+ and Yarn:
|
|
@@ -104,7 +170,7 @@ xfidelity [-d --dir <directory>] [-c --configServer <url>] [-a --archetype <arch
|
|
|
104
170
|
- `-d --dir <directory>`: Specify the root directory to analyze (default: current directory)
|
|
105
171
|
- `-c --configServer <url>`: URL to fetch the configuration from. eg. https://localhost:8888
|
|
106
172
|
- `-a --archetype <archetype>`: Archetype to use for analysis (default: 'node-fullstack')
|
|
107
|
-
- `-m --mode <mode>`: Run mode: '
|
|
173
|
+
- `-m --mode <mode>`: Run mode: 'client' or 'server' (default: 'client')
|
|
108
174
|
- `-p --port <port>`: Port number for server mode (default: 8888)
|
|
109
175
|
- `-o --openaiEnabled <boolean>`: Enable OpenAI analysis (default: false)
|
|
110
176
|
- `-t --telemetryCollector <url>`: The URL telemetry data will be sent to for usage analysis
|
|
@@ -119,120 +185,199 @@ xfidelity --configServer https://localhost:8888
|
|
|
119
185
|
# Analyze parent directory with java-microservice archetype and enable OpenAI analysis
|
|
120
186
|
xfidelity -d .. -a java-microservice -c https://localhost:8888 -o true
|
|
121
187
|
|
|
122
|
-
#
|
|
188
|
+
#Run in server mode with custom port and specify telemetry collector
|
|
123
189
|
xfidelity --mode server --port 9999 -t https://telemetry.example.com
|
|
124
190
|
|
|
125
191
|
# Use local config and rules
|
|
126
192
|
xfidelity -l /path/to/local/config
|
|
127
|
-
|
|
128
193
|
```
|
|
129
194
|
|
|
130
|
-
|
|
195
|
+
## Configuration
|
|
131
196
|
|
|
132
|
-
|
|
197
|
+
x-fidelity uses archetypes to define project-specific configurations. Archetypes are now managed as JSON files, which can be stored locally or on a remote server.
|
|
133
198
|
|
|
134
|
-
|
|
135
|
-
yarn start-server
|
|
136
|
-
```
|
|
199
|
+
### Archetype Structure
|
|
137
200
|
|
|
138
|
-
|
|
201
|
+
Archetypes specify:
|
|
139
202
|
|
|
140
|
-
|
|
141
|
-
|
|
203
|
+
- Rules to apply
|
|
204
|
+
- Operators to use
|
|
205
|
+
- Facts to gather
|
|
206
|
+
- Dependency version requirements
|
|
207
|
+
- Standard directory structure
|
|
208
|
+
- File patterns to include or exclude
|
|
209
|
+
|
|
210
|
+
Example archetype JSON structure:
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
{
|
|
214
|
+
"rules": ["rule1", "rule2"],
|
|
215
|
+
"operators": ["operator1", "operator2"],
|
|
216
|
+
"facts": ["fact1", "fact2"],
|
|
217
|
+
"config": {
|
|
218
|
+
"minimumDependencyVersions": {
|
|
219
|
+
"dependency1": "^1.0.0",
|
|
220
|
+
"dependency2": "^2.0.0"
|
|
221
|
+
},
|
|
222
|
+
"standardStructure": {
|
|
223
|
+
"src": {
|
|
224
|
+
"components": null,
|
|
225
|
+
"utils": null
|
|
226
|
+
},
|
|
227
|
+
"tests": null
|
|
228
|
+
},
|
|
229
|
+
"blacklistPatterns": [".*\\/\\..*", ".*\\/(dist|build)(\\/.*|$)"],
|
|
230
|
+
"whitelistPatterns": [".*\\.(ts|tsx|js|jsx)$"]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
142
233
|
```
|
|
143
234
|
|
|
144
|
-
|
|
235
|
+
### Local Configuration
|
|
236
|
+
|
|
237
|
+
To use local configuration files for archetypes and rules, use the `-l` or `--localConfig` option:
|
|
145
238
|
|
|
146
239
|
```sh
|
|
147
|
-
xfidelity
|
|
240
|
+
xfidelity -l /path/to/local/config
|
|
148
241
|
```
|
|
149
242
|
|
|
150
|
-
|
|
243
|
+
The local config directory should contain:
|
|
244
|
+
- Archetype JSON files (e.g., `node-fullstack.json`)
|
|
245
|
+
- A `rules` subdirectory containing rule JSON files
|
|
246
|
+
|
|
247
|
+
You can override default archetypes or add new ones by placing the corresponding JSON files in the local config directory.
|
|
248
|
+
|
|
249
|
+
### Remote Configuration
|
|
250
|
+
|
|
251
|
+
To use a remote configuration server, use the `-c` or `--configServer` option:
|
|
151
252
|
|
|
152
253
|
```sh
|
|
153
|
-
|
|
154
|
-
xfidelity --mode server
|
|
254
|
+
xfidelity -c https://config-server.example.com
|
|
155
255
|
```
|
|
156
256
|
|
|
157
|
-
|
|
257
|
+
The remote server should provide endpoints to serve archetype and rule configurations.
|
|
158
258
|
|
|
159
|
-
|
|
259
|
+
## Hosting Config Servers
|
|
160
260
|
|
|
161
|
-
-
|
|
162
|
-
- Operators to use
|
|
163
|
-
- Facts to gather
|
|
164
|
-
- Dependency version requirements
|
|
165
|
-
- Standard directory structure
|
|
166
|
-
- File patterns to include or exclude
|
|
261
|
+
x-fidelity allows for centrally managed, hot-updatable custom rulesets that can be executed within managed CI pipelines and locally, ensuring consistency of applied rules. Here's an overview of the setup required:
|
|
167
262
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
```
|
|
263
|
+
1. Set up a Node.js host environment (Docker containerization recommended).
|
|
264
|
+
2. Create a GitHub repository to host your archetypes and rules.
|
|
265
|
+
3. Clone the GitHub repository to the server filesystem.
|
|
266
|
+
4. Install the x-fidelity CLI on the server.
|
|
267
|
+
5. Configure the CLI to:
|
|
268
|
+
- Run on startup in server mode (`--mode server`)
|
|
269
|
+
- Point to your rules directory cloned from GitHub (`--localConfig ../rule-repo/config`)
|
|
270
|
+
- Optionally set the port to listen on (`--port <port>`)
|
|
271
|
+
6. Create a simple CI pipeline step 'framework fidelity' after git repo clone to workspace:
|
|
272
|
+
- Install the x-fidelity CLI
|
|
273
|
+
- Run the CLI on the checked-out repo, pointing to the server (`--configServer http://my-server:8888`)
|
|
274
|
+
|
|
275
|
+
### Docker Example
|
|
276
|
+
|
|
277
|
+
Here's a basic Docker setup for hosting an x-fidelity config server:
|
|
184
278
|
|
|
185
|
-
|
|
279
|
+
```dockerfile
|
|
280
|
+
FROM node:18
|
|
186
281
|
|
|
187
|
-
x-fidelity
|
|
282
|
+
# Install x-fidelity
|
|
283
|
+
RUN yarn global add x-fidelity
|
|
188
284
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
- File count
|
|
192
|
-
- Failure count
|
|
193
|
-
- Host information (platform, CPU, memory)
|
|
194
|
-
- User information (anonymized username, home directory, shell)
|
|
285
|
+
# Clone your rules repository
|
|
286
|
+
RUN git clone https://github.com/your-org/x-fidelity-rules.git /rules
|
|
195
287
|
|
|
196
|
-
|
|
288
|
+
# Set up the start command
|
|
289
|
+
CMD ["x-fidelity", "--mode", "server", "--localConfig", "/rules", "--port", "8888"]
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Build and run the Docker container:
|
|
197
293
|
|
|
198
294
|
```sh
|
|
199
|
-
|
|
295
|
+
docker build -t x-fidelity-server .
|
|
296
|
+
docker run -p 8888:8888 x-fidelity-server
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### CI Pipeline Integration
|
|
300
|
+
|
|
301
|
+
In your CI pipeline (e.g., GitHub Actions, GitLab CI, Jenkins), add a step to run x-fidelity:
|
|
302
|
+
|
|
303
|
+
```yaml
|
|
304
|
+
steps:
|
|
305
|
+
- name: Check out code
|
|
306
|
+
uses: actions/checkout@v2
|
|
307
|
+
|
|
308
|
+
- name: Install x-fidelity
|
|
309
|
+
run: yarn global add x-fidelity
|
|
310
|
+
|
|
311
|
+
- name: Run x-fidelity
|
|
312
|
+
run: xfidelity --configServer http://x-fidelity-server:8888
|
|
200
313
|
```
|
|
201
314
|
|
|
202
|
-
|
|
315
|
+
This setup allows you to maintain a centralized set of rules and archetypes that can be easily updated and applied across all your projects.
|
|
203
316
|
|
|
204
317
|
## Extending x-fidelity
|
|
205
318
|
|
|
206
|
-
x-fidelity is designed to be highly extensible:
|
|
319
|
+
x-fidelity is designed to be highly extensible. You can add custom rules, operators, facts, and archetypes:
|
|
320
|
+
|
|
321
|
+
1. **Custom Rules**: Add new JSON rule files in the `rules` subdirectory of your local config or on your config server.
|
|
322
|
+
2. **Custom Operators**: Implement new operators and add them to your x-fidelity fork or plugin.
|
|
323
|
+
3. **Custom Facts**: Create new fact providers and add them to your x-fidelity fork or plugin.
|
|
324
|
+
4. **New Archetypes**: Define new archetypes as JSON files in your local config directory or on your config server.
|
|
325
|
+
|
|
326
|
+
Example of a custom rule JSON file (`my-custom-rule.json`):
|
|
327
|
+
|
|
328
|
+
```json
|
|
329
|
+
{
|
|
330
|
+
"name": "my-custom-rule",
|
|
331
|
+
"conditions": {
|
|
332
|
+
"all": [
|
|
333
|
+
{
|
|
334
|
+
"fact": "fileData",
|
|
335
|
+
"path": "$.fileContent",
|
|
336
|
+
"operator": "fileContains",
|
|
337
|
+
"value": "TODO:"
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
},
|
|
341
|
+
"event": {
|
|
342
|
+
"type": "violation",
|
|
343
|
+
"params": {
|
|
344
|
+
"message": "TODO comments should be resolved before committing",
|
|
345
|
+
"level": "warning",
|
|
346
|
+
"details": {
|
|
347
|
+
"fact": "fileData",
|
|
348
|
+
"path": "$.filePath"
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
```
|
|
207
354
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
4. **New Archetypes**: Define new archetypes in `src/archetypes` and include them in `src/archetypes/index.ts`.
|
|
355
|
+
Note on rule event types:
|
|
356
|
+
- Events of type "violation" are treated as warnings and do not cause the tool to return an error code.
|
|
357
|
+
- Events of type "fatality" are strictly enforced and will cause the tool to return an error code 1.
|
|
212
358
|
|
|
213
|
-
Example of
|
|
359
|
+
Example of a custom archetype JSON file (`my-custom-archetype.json`):
|
|
214
360
|
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
'my-framework': '^2.0.0'
|
|
361
|
+
```json
|
|
362
|
+
{
|
|
363
|
+
"rules": ["myCustomRule", "standardRule1", "standardRule2"],
|
|
364
|
+
"operators": ["myCustomOperator", "standardOperator1"],
|
|
365
|
+
"facts": ["myCustomFact", "standardFact1"],
|
|
366
|
+
"config": {
|
|
367
|
+
"minimumDependencyVersions": {
|
|
368
|
+
"my-framework": "^2.0.0"
|
|
224
369
|
},
|
|
225
|
-
standardStructure: {
|
|
226
|
-
src: {
|
|
227
|
-
components: null,
|
|
228
|
-
utils: null
|
|
370
|
+
"standardStructure": {
|
|
371
|
+
"src": {
|
|
372
|
+
"components": null,
|
|
373
|
+
"utils": null
|
|
229
374
|
},
|
|
230
|
-
tests: null
|
|
375
|
+
"tests": null
|
|
231
376
|
},
|
|
232
|
-
blacklistPatterns: [
|
|
233
|
-
whitelistPatterns: [
|
|
377
|
+
"blacklistPatterns": [".*\\/\\..*", ".*\\/(dist|build)(\\/.*|$)"],
|
|
378
|
+
"whitelistPatterns": [".*\\.(ts|tsx|js|jsx)$"]
|
|
234
379
|
}
|
|
235
|
-
}
|
|
380
|
+
}
|
|
236
381
|
```
|
|
237
382
|
|
|
238
383
|
## OpenAI Integration
|
|
@@ -261,78 +406,21 @@ export OPENAI_MODEL=gpt-4 # Optional, default is gpt-4o
|
|
|
261
406
|
> [!IMPORTANT]
|
|
262
407
|
> Be aware of potential costs and data privacy concerns when using OpenAI's API.
|
|
263
408
|
|
|
264
|
-
## Local Configuration
|
|
265
|
-
|
|
266
|
-
You can now use local configuration files for archetypes and rules. To use local configuration, use the `-l` or `--localConfig` option:
|
|
267
|
-
|
|
268
|
-
```sh
|
|
269
|
-
xfidelity -l /path/to/local/config
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
The local config directory should contain:
|
|
273
|
-
|
|
274
|
-
- Archetype configuration files (e.g., `node-fullstack.json`)
|
|
275
|
-
- A `rules` subdirectory containing rule files
|
|
276
|
-
|
|
277
|
-
## Hosting Config Servers
|
|
278
|
-
|
|
279
|
-
To host a config server for x-fidelity:
|
|
280
|
-
|
|
281
|
-
1. Set up a Node.js server (e.g., Express.js)
|
|
282
|
-
2. Implement endpoints for archetype configurations and rules
|
|
283
|
-
3. Ensure security, scalability, and performance
|
|
284
|
-
4. Use HTTPS and implement proper authentication
|
|
285
|
-
5. Consider using a CDN for global distribution
|
|
286
|
-
|
|
287
|
-
Example server setup:
|
|
288
|
-
|
|
289
|
-
```javascript
|
|
290
|
-
const express = require('express');
|
|
291
|
-
const app = express();
|
|
292
|
-
|
|
293
|
-
app.get('/archetypes/:archetype', (req, res) => {
|
|
294
|
-
// Fetch and return archetype configuration
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
app.get('/archetypes/:archetype/rules/:rule', (req, res) => {
|
|
298
|
-
// Fetch and return specific rule
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
app.listen(8888, () => {
|
|
302
|
-
console.log('Config server running on port 8888');
|
|
303
|
-
});
|
|
304
|
-
```
|
|
305
|
-
|
|
306
409
|
## Best Practices
|
|
307
410
|
|
|
308
|
-
1. **Version Control**: Keep your x-fidelity configurations in version control.
|
|
411
|
+
1. **Version Control**: Keep your x-fidelity configurations (archetypes and rules) in version control.
|
|
309
412
|
2. **Continuous Integration**: Integrate x-fidelity checks into your CI/CD pipeline.
|
|
310
413
|
3. **Regular Updates**: Keep your archetypes, rules, and dependencies up to date.
|
|
311
414
|
4. **Documentation**: Document custom rules, operators, and archetypes for your team.
|
|
312
415
|
5. **Gradual Implementation**: When introducing x-fidelity to an existing project, start with basic checks and gradually increase strictness.
|
|
313
416
|
6. **Team Alignment**: Ensure your team understands and agrees on the rules being enforced.
|
|
314
417
|
7. **Performance**: Be mindful of the performance impact, especially for large codebases.
|
|
418
|
+
8. **Centralized Management**: Use a config server to manage and distribute your archetypes and rules across projects.
|
|
315
419
|
|
|
316
420
|
## Contributing
|
|
317
421
|
|
|
318
422
|
Contributions to x-fidelity are welcome! Please refer to the `CONTRIBUTING.md` file for guidelines on how to contribute to this project.
|
|
319
423
|
|
|
320
|
-
## Linting
|
|
321
|
-
|
|
322
|
-
This project uses ESLint for static code analysis. To run the linter:
|
|
323
|
-
|
|
324
|
-
```sh
|
|
325
|
-
yarn lint
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
To automatically fix linting issues:
|
|
329
|
-
|
|
330
|
-
```sh
|
|
331
|
-
yarn lint:fix
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
ESLint is also integrated into the CI pipeline and runs alongside unit tests in GitHub Actions.
|
|
335
|
-
|
|
336
424
|
## License
|
|
337
425
|
|
|
338
426
|
This project is licensed under the MIT License. See the `LICENSE` file for details.
|
package/dist/archetypes/index.js
CHANGED
|
@@ -1,62 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.archetypes = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
frontend: null,
|
|
17
|
-
server: null
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
blacklistPatterns: [
|
|
21
|
-
'.*\\/\\..*', // dot files
|
|
22
|
-
'.*\\.(log|lock)$', // file extensions blacklisted
|
|
23
|
-
'.*\\/(dist|coverage|build|node_modules)(\\/.*|$)' // directory names blacklisted
|
|
24
|
-
],
|
|
25
|
-
whitelistPatterns: [
|
|
26
|
-
'.*\\.(ts|tsx|js|jsx|md)$' // file extensions whitelisted
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
'java-microservice': {
|
|
31
|
-
rules: ['sensitiveLogging-iterative', 'outdatedFramework-global', 'noDatabases-iterative', 'nonStandardDirectoryStructure-global'],
|
|
32
|
-
operators: ['fileContains', 'outdatedFramework', 'nonStandardDirectoryStructure'],
|
|
33
|
-
facts: ['repoFilesystemFacts', 'repoDependencyFacts'],
|
|
34
|
-
config: {
|
|
35
|
-
minimumDependencyVersions: {
|
|
36
|
-
'spring-boot-starter': '^2.5.0',
|
|
37
|
-
'spring-boot-starter-web': '^2.5.0'
|
|
38
|
-
},
|
|
39
|
-
standardStructure: {
|
|
40
|
-
src: {
|
|
41
|
-
main: {
|
|
42
|
-
java: null,
|
|
43
|
-
resources: null
|
|
44
|
-
},
|
|
45
|
-
test: {
|
|
46
|
-
java: null,
|
|
47
|
-
resources: null
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
blacklistPatterns: [
|
|
52
|
-
'.*\\/\\..*', // dot files
|
|
53
|
-
'.*\\.(log|lock)$', // file extensions blacklisted
|
|
54
|
-
'.*\\/(target|build|out|dist|coverage|build|node_modules)(\\/.*|$)' // directory names blacklisted
|
|
55
|
-
],
|
|
56
|
-
whitelistPatterns: [
|
|
57
|
-
'.*\\.(java|xml|properties|yml)$',
|
|
58
|
-
'.*\\/pom\\.xml$'
|
|
59
|
-
]
|
|
60
|
-
}
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const logger_1 = __importDefault(require("../utils/logger"));
|
|
33
|
+
function loadArchetypeFromJson(fileName) {
|
|
34
|
+
const filePath = path.join(__dirname, fileName);
|
|
35
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(fileContent);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
logger_1.default.error(`Error parsing JSON in file ${fileName}: ${error}`);
|
|
41
|
+
return {}; // Return an empty object as a fallback
|
|
61
42
|
}
|
|
43
|
+
}
|
|
44
|
+
exports.archetypes = {
|
|
45
|
+
'node-fullstack': loadArchetypeFromJson('node-fullstack.json'),
|
|
46
|
+
'java-microservice': loadArchetypeFromJson('java-microservice.json')
|
|
62
47
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"rules": [
|
|
3
|
+
"sensitiveLogging-iterative",
|
|
4
|
+
"outdatedFramework-global",
|
|
5
|
+
"noDatabases-iterative",
|
|
6
|
+
"nonStandardDirectoryStructure-global"
|
|
7
|
+
],
|
|
8
|
+
"operators": [
|
|
9
|
+
"fileContains",
|
|
10
|
+
"outdatedFramework",
|
|
11
|
+
"nonStandardDirectoryStructure"
|
|
12
|
+
],
|
|
13
|
+
"facts": [
|
|
14
|
+
"repoFilesystemFacts",
|
|
15
|
+
"repoDependencyFacts"
|
|
16
|
+
],
|
|
17
|
+
"config": {
|
|
18
|
+
"minimumDependencyVersions": {
|
|
19
|
+
"spring-boot-starter": "^2.5.0",
|
|
20
|
+
"spring-boot-starter-web": "^2.5.0"
|
|
21
|
+
},
|
|
22
|
+
"standardStructure": {
|
|
23
|
+
"src": {
|
|
24
|
+
"main": {
|
|
25
|
+
"java": null,
|
|
26
|
+
"resources": null
|
|
27
|
+
},
|
|
28
|
+
"test": {
|
|
29
|
+
"java": null,
|
|
30
|
+
"resources": null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"blacklistPatterns": [
|
|
35
|
+
".*\\/\\..*",
|
|
36
|
+
".*\\.(log|lock)$",
|
|
37
|
+
".*\\/(target|build|out|dist|coverage|build|node_modules)(\\/.*|$)"
|
|
38
|
+
],
|
|
39
|
+
"whitelistPatterns": [
|
|
40
|
+
".*\\.(java|xml|properties|yml)$",
|
|
41
|
+
".*\\/pom\\.xml$"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|