Skip to content

Commit 3f5f208

Browse files
committed
add pos-cli check command
1 parent 4aa5444 commit 3f5f208

12 files changed

Lines changed: 813 additions & 1 deletion

File tree

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,136 @@ Example: `pos-cli audit`
9191

9292
This command checks your application files for issues using static analysis, helping you maintain code quality and identify potential errors.
9393

94+
### Liquid Code Quality Check
95+
96+
pos-cli provides a powerful Liquid code quality checker powered by platformos-check. This helps you catch issues early, enforce best practices, and maintain high-quality code.
97+
98+
#### Initialize Configuration
99+
100+
Before running checks, you can create a `.platformos-check.yml` configuration file to customize which checks to run:
101+
102+
pos-cli check init [path]
103+
104+
Example: `pos-cli check init`
105+
106+
This creates a `.platformos-check.yml` file that:
107+
- Extends the recommended platformos-check configuration
108+
- Ignores `node_modules/**` by default
109+
- Includes all available settings as comments for easy customization
110+
111+
#### Run Checks
112+
113+
To check your Liquid code quality, use:
114+
115+
pos-cli check run [path]
116+
117+
Example: `pos-cli check run`
118+
119+
This command analyzes Liquid templates for common issues, syntax errors, and best practices violations. By default, it checks the current directory, but you can specify a path to check a specific directory.
120+
121+
The output includes:
122+
- **Severity levels**: Errors, warnings, and info messages color-coded for easy identification
123+
- **Code snippets**: Shows the actual problematic code with line numbers
124+
- **Grouped by file**: Offenses are organized by file for better readability
125+
- **Summary counts**: Total offenses broken down by severity
126+
127+
#### Options
128+
129+
- `-a` - Enable automatic fixing of issues where possible
130+
- `-f <format>` - Output format: `text` (default) or `json`
131+
- `-s, --silent` - Only show errors, no success messages
132+
133+
#### Examples
134+
135+
Check current directory:
136+
137+
pos-cli check run
138+
139+
Check specific directory:
140+
141+
pos-cli check run ./app/views
142+
143+
Auto-fix issues:
144+
145+
pos-cli check run -a
146+
147+
JSON output for CI/CD:
148+
149+
pos-cli check run -f json
150+
151+
Silent mode (no success message):
152+
153+
pos-cli check run -s
154+
155+
Combined options:
156+
157+
pos-cli check run -a -f json
158+
159+
The command exits with code 0 if no issues are found, or 1 if issues are detected, making it suitable for CI/CD pipelines.
160+
161+
#### Output Format
162+
163+
**Text output** displays offenses grouped by file with code snippets:
164+
165+
```
166+
3 offenses found in 1 file:
167+
3 warnings
168+
169+
app/views/pages/index.liquid
170+
171+
[warning] UndefinedObject
172+
Unknown object 'user' used.
173+
174+
5 <p>{{ user.name }}</p>
175+
```
176+
177+
**JSON output** provides structured data with severity counts:
178+
179+
```json
180+
{
181+
"offenseCount": 3,
182+
"fileCount": 1,
183+
"errorCount": 0,
184+
"warningCount": 3,
185+
"infoCount": 0,
186+
"files": [
187+
{
188+
"path": "app/views/pages/index.liquid",
189+
"offenses": [...],
190+
"errorCount": 0,
191+
"warningCount": 3,
192+
"infoCount": 0
193+
}
194+
]
195+
}
196+
```
197+
198+
#### Configuration File
199+
200+
After running `pos-cli check init`, you can customize `.platformos-check.yml`:
201+
202+
```yaml
203+
extends: platformos-check:recommended
204+
ignore:
205+
- node_modules/**
206+
- dist/**
207+
208+
# Customize individual checks
209+
UndefinedObject:
210+
enabled: true
211+
severity: error # error (0), warning (1), or info (2)
212+
213+
DeprecatedFilter:
214+
enabled: true
215+
severity: warning
216+
```
217+
218+
The configuration file controls:
219+
- Which checks are enabled/disabled
220+
- Severity levels for each check
221+
- File patterns to ignore
222+
- Check-specific settings
223+
94224
### Reading Logs
95225
96226
Use the `logs` command to access errors and logs that you or the system logs:

bin/pos-cli-check-init.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
import { program } from 'commander';
3+
import { initConfig } from '../lib/check.js';
4+
5+
program
6+
.name('pos-cli check init')
7+
.description('initialize .platformos-check.yml configuration file')
8+
.argument('[path]', 'path to initialize config in (defaults to current directory)', process.cwd())
9+
.action(async (configPath) => {
10+
await initConfig(configPath);
11+
});
12+
13+
program.parse(process.argv);

bin/pos-cli-check-run.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
import path from 'path';
3+
import { program } from 'commander';
4+
import { run } from '../lib/check.js';
5+
6+
program
7+
.name('pos-cli check run')
8+
.description('check Liquid code quality with platformos-check linter')
9+
.argument('[path]', 'path to check (defaults to current directory)', process.cwd())
10+
.option('-a', 'enable automatic fixing')
11+
.option('-f <format>', 'output format: text or json', 'text')
12+
.option('-s, --silent', 'only show errors, no success messages')
13+
.action(async (checkPath, options) => {
14+
const absolutePath = path.resolve(checkPath);
15+
16+
await run({
17+
path: absolutePath,
18+
autoFix: options.a || false,
19+
format: options.f || 'text',
20+
silent: options.silent || false
21+
});
22+
});
23+
24+
program.parse(process.argv);

bin/pos-cli-check.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
import { program } from 'commander';
3+
4+
program
5+
.name('pos-cli check')
6+
.command('run [path]', 'check Liquid code quality with platformos-check linter')
7+
.command('init [path]', 'initialize .platformos-check.yml configuration file')
8+
.parse(process.argv);

bin/pos-cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ program
1919
.version(version, '-v, --version')
2020
.command('archive', 'create an archive only (no deployment)')
2121
.command('audit', 'check your code for deprecations, recommendations, errors')
22-
.command('constants', 'manage constants')
22+
.command('check', 'check Liquid code quality with platformos-check linter')
2323
.command('clone', 'clone instances')
24+
.command('constants', 'manage constants')
2425
.command('data', 'export, import or clean data on instance')
2526
.command('deploy <environment>', 'deploy code to environment').alias('d')
2627
.command('env', 'manage environments')

0 commit comments

Comments
 (0)