Skip to content

feat: add ls-lint linter #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trunk check enable {linter}

| Technology | Linters |
| --------------- | ------------------------------------------------------------------------------------------------------------------------ |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale], [ls-lint] |
| Ansible | [ansible-lint] |
| Apex | [pmd] |
| Bash | [shellcheck], [shfmt] |
Expand Down Expand Up @@ -136,6 +136,7 @@ trunk check enable {linter}
[isort]: https://github.com/PyCQA/isort#readme
[ktlint]: https://github.com/pinterest/ktlint#readme
[kube-linter]: https://github.com/stackrox/kube-linter#readme
[ls-lint]: https://github.com/loeffel-io/ls-lint#readme
[markdownlint]: https://github.com/DavidAnson/markdownlint#readme
[markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2#readme
[markdown-table-prettify]: https://github.com/darkriszty/MarkdownTablePrettify-VSCodeExt#readme
Expand Down
71 changes: 71 additions & 0 deletions linters/ls-lint/helpers/json-to-sarif.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env node
"use strict";

const fs = require("fs");

const directory = ".dir";

const toSarif = (path, rule, message) => ({
level: "error",
locations: [
{
physicalLocation: {
artifactLocation: {
uri: path,
},
},
},
],
message: {
text: message,
},
ruleId: rule,
});

const loadJsonSafe = () => {
try {
const inputData = JSON.parse(fs.readFileSync(0, "utf-8"));
return inputData;
} catch {
return [];
}
};

const main = () => {
const results = [];
const inputData = loadJsonSafe();

for (const [path, descriptor] of Object.entries(inputData)) {
// src/directory { '.dir': [ 'kebabcase' ] }
for (const [key, rules] of Object.entries(descriptor)) {
// .dir [ 'kebabcase' ]
const type = key === directory ? "Directory" : "File";

for (const rule of rules) {
// kebabcase
const message = `${type} ${path} does not comply with rule ${rule}`;
results.push(toSarif(path, rule, message));
}
}
}

const output = {
$schema:
"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
version: "2.1.0",
runs: [
{
results: results,
tool: {
driver: {
name: "ls-lint",
},
},
},
],
};

console.log(JSON.stringify(output, null, 2));
};

main();
3 changes: 3 additions & 0 deletions linters/ls-lint/ls_lint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { linterCheckTest } from "tests";

linterCheckTest({ linterName: "ls-lint" });
40 changes: 40 additions & 0 deletions linters/ls-lint/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# yaml-language-server: $schema=https://static.trunk.io/pub/trunk-yaml-schema.json

version: 0.1
tools:
definitions:
- name: ls-lint
shims:
- ls-lint
runtime: node
known_good_version: 2.3.0
package: "@ls-lint/ls-lint"
lint:
definitions:
- name: ls-lint
files:
- ALL
tools:
- ls-lint
direct_configs:
- .ls-lint.yml
hold_the_line: false
version_command:
parse_regex: ${semver}
run: ls-lint --version
known_good_version: 2.3.0
suggest_if: config_present
description: Lints thousands of files and directories in milliseconds
commands:
- name: lint
target: .
batch: true
output: sarif
success_codes:
- 0
- 1
read_output_from: stderr
parser:
runtime: node
run: ${plugin}/helpers/json-to-sarif.js
run: ls-lint --workdir ${workspace} --error-output-format json
21 changes: 21 additions & 0 deletions linters/ls-lint/test_data/ls_lint_v2.3.0_snake_case.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter ls-lint test snake_case 1`] = `
{
"issues": [],
"lintActions": [],
"taskFailures": [
{
"details": StringMatching /\\.\\*\\$/m,
"message": ".",
"name": "ls-lint",
},
{
"details": StringMatching /\\.\\*\\$/m,
"message": ".",
"name": "ls-lint",
},
],
"unformattedFiles": [],
}
`;
1 change: 1 addition & 0 deletions linters/ls-lint/test_data/snake_case.in.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Hello