Skip to content
Merged
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
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ jobs:
- name: Verify Knip policy
run: bash scripts/test-knip-policy.sh

# ==========================================================================
# JOB: VUE POLICY INTEGRATION
# ==========================================================================
vue-policy:
name: Test / Vue layer under Qlty
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false

- name: Install Qlty
uses: qltysh/qlty-action/install@v2

- name: Verify Vue layer
run: bash scripts/test-vue-policy.sh

# ==========================================================================
# JOB: TERRAFORM POLICY INTEGRATION
# ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ composer test # PHPUnit suite for the sniffs and PHPStan rules
composer test:coverage # With Clover coverage report (requires Xdebug)
composer test:mutation # Infection mutation gate on the diff against origin/master
npm run test:js # Vitest suite for the ESLint rules
bash scripts/test-<tool>-policy.sh # Qlty consumer integration test for knip, shared, swift, terraform, trivy or zizmor
bash scripts/test-<tool>-policy.sh # Qlty consumer integration test for knip, shared, swift, terraform, trivy, vue or zizmor
```

Single test file or method:
Expand Down
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,41 @@ a four-space indent, because Biome cannot format `.vue` markup. To match, the sh
well as kebab-case under any `components/` directory, so a component's tests and stories can share its name
(`UserCard.test.ts`).

Through Qlty, the eslint plugin sandbox installs only `eslint`, `jest` and `prettier` by default, so the config's
imports fail to resolve. Widen the install filter in your `.qlty/qlty.toml`:
Through Qlty, enable the eslint plugin on your `package.json`. Its sandbox installs only `eslint`, `jest` and
`prettier` from that file by default, so widen the filter or the config's imports fail to resolve:

```toml
[plugins.definitions.eslint]
[[plugin]]
name = "eslint"
package_file = "package.json"
package_filters = [
"@sinemacula/coding-standards", "typescript-eslint", "@typescript-eslint", "eslint-plugin-jsdoc",
"yaml-eslint-parser",
]
```

With the Vue layer, add its packages too:
With the Vue layer, add its packages to the filter, and route `.vue` files to ESLint. Qlty has no `vue` file type and
hands ESLint only JavaScript and TypeScript, so without the last two blocks no single-file component is linted:

```toml
[plugins.definitions.eslint]
[[plugin]]
name = "eslint"
package_file = "package.json"
package_filters = [
"@sinemacula/coding-standards", "typescript-eslint", "@typescript-eslint", "eslint-plugin-jsdoc",
"yaml-eslint-parser", "eslint-plugin-vue", "vue-eslint-parser", "eslint-plugin-check-file",
]

[file_types.vue]
globs = ["*.vue", "**/*.vue"]

[plugins.definitions.eslint]
file_types = ["javascript", "typescript", "jsx", "tsx", "vue"]
```

The routing stays with the Vue layer rather than the shared source, because ESLint cannot parse a `.vue` file without
that layer's parser.

### TypeScript (tsconfig)

Extend the shared base from your `tsconfig.json`:
Expand Down Expand Up @@ -703,7 +717,7 @@ composer format # format via qlty
composer smells # duplication / complexity smells via qlty
npm run test:js # Vitest suite for the ESLint rules
npm run lint:js # ESLint over this package's own rules
bash scripts/test-<tool>-policy.sh # exported policy integration tests (knip, shared, swift, terraform, trivy, zizmor)
bash scripts/test-<tool>-policy.sh # exported policy integration tests (knip, shared, swift, terraform, trivy, vue, zizmor)
```

The Swift policy test needs macOS.
Expand Down
74 changes: 74 additions & 0 deletions scripts/test-vue-policy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

set -euo pipefail

if ! command -v qlty >/dev/null 2>&1; then
echo "The Qlty CLI is required: https://docs.qlty.sh/cli/quickstart" >&2
exit 1
fi

repository_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
fixtures="${repository_root}/tests/vue-consumer/Fixtures"

# TMPDIR is often unset; without a fallback mktemp targets the filesystem root.
vue_consumer_dir="$(mktemp -d "${TMPDIR:-/tmp}/coding-standards-vue.XXXXXX")"

cleanup() {
rm -rf -- "${vue_consumer_dir}"
}

trap cleanup EXIT

# The consumer's config is the README's Vue example verbatim, so the docs cannot
# drift from what this proves.
documented_config="$(awk '
/^With the Vue layer, add its packages/ { found = 1; next }
found && /^```toml$/ { inside = 1; next }
inside && /^```$/ { exit }
inside { print }
' "${repository_root}/README.md")"

if [[ -z ${documented_config} ]]; then
echo "Expected the README to document the Qlty config for the Vue layer."
exit 1
fi

mkdir -p "${vue_consumer_dir}/.qlty/configs" "${vue_consumer_dir}/src/components"
sed "s|__SOURCE_DIRECTORY__|${repository_root}|g" \
"${repository_root}/tests/vue-consumer/qlty.toml.template" \
> "${vue_consumer_dir}/.qlty/qlty.toml"
printf '\n%s\n' "${documented_config}" >> "${vue_consumer_dir}/.qlty/qlty.toml"

# qlty keys its tool sandbox on the package file, so a content-addressed tarball
# stops a local rerun from linting with a stale copy of this package.
packed="$(cd "${repository_root}" && npm pack --silent --pack-destination "${vue_consumer_dir}")"
tarball="coding-standards-$(shasum -a 256 "${vue_consumer_dir}/${packed}" | cut -c1-12).tgz"
mv "${vue_consumer_dir}/${packed}" "${vue_consumer_dir}/${tarball}"

sed "s|__PACKAGE_TARBALL__|${tarball}|" "${fixtures}/package.json.fixture" > "${vue_consumer_dir}/package.json"
cp "${fixtures}/eslint.config.mjs.fixture" "${vue_consumer_dir}/.qlty/configs/eslint.config.mjs"
cp "${fixtures}/ListItems.vue.fixture" "${vue_consumer_dir}/src/components/ListItems.vue"

git -C "${vue_consumer_dir}" init --quiet --initial-branch=master

cd "${vue_consumer_dir}"

set +e
scan_output="$(qlty check --all --no-cache --filter=eslint 2>&1)"
set -e

fail() {
echo "$1"
echo "${scan_output}"
exit 1
}

if [[ ${scan_output} != *"src/components/ListItems.vue"* ]]; then
fail "Expected ESLint to lint the single-file component."
fi

for rule in vue/no-use-v-if-with-v-for vue/require-v-for-key; do
if [[ ${scan_output} != *"eslint:${rule}"* ]]; then
fail "Expected the Vue layer to report ${rule}."
fi
done
3 changes: 3 additions & 0 deletions tests/vue-consumer/Fixtures/ListItems.vue.fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div v-if="visible" v-for="item in items">{{ item }}</div>
</template>
4 changes: 4 additions & 0 deletions tests/vue-consumer/Fixtures/eslint.config.mjs.fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sm from '@sinemacula/coding-standards/js/eslint';
import vue from '@sinemacula/coding-standards/js/eslint/vue';

export default [...sm, ...vue];
17 changes: 17 additions & 0 deletions tests/vue-consumer/Fixtures/package.json.fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "vue-consumer",
"version": "1.0.0",
"private": true,
"type": "module",
"devDependencies": {
"@sinemacula/coding-standards": "file:./__PACKAGE_TARBALL__",
"eslint": "^9.0.0",
"eslint-plugin-check-file": "^3.0.0",
"eslint-plugin-jsdoc": "^63.0.13",
"eslint-plugin-vue": "^10.0.0",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0",
"vue-eslint-parser": "^10.0.0",
"yaml-eslint-parser": "^2.1.0"
}
}
9 changes: 9 additions & 0 deletions tests/vue-consumer/qlty.toml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config_version = "0"

[[source]]
name = "default"
default = true

[[source]]
name = "sinemacula"
directory = "__SOURCE_DIRECTORY__"
Loading