From 1fd77d4c32977160543345cc2119bad9bebe781d Mon Sep 17 00:00:00 2001 From: Ben Carey Date: Tue, 17 Nov 2026 15:39:58 -0500 Subject: [PATCH] fix: route .vue files to ESLint under qlty when the Vue layer is enabled qlty's eslint plugin is only handed JavaScript and TypeScript, so a repo on the Vue layer linted no single-file components. The README now gives the file type and routing to add, plus the package_file the eslint sandbox needs, and a consumer integration test runs that exact config. --- .github/workflows/tests.yml | 19 +++++ CONTRIBUTING.md | 2 +- README.md | 26 +++++-- scripts/test-vue-policy.sh | 74 +++++++++++++++++++ .../Fixtures/ListItems.vue.fixture | 3 + .../Fixtures/eslint.config.mjs.fixture | 4 + .../Fixtures/package.json.fixture | 17 +++++ tests/vue-consumer/qlty.toml.template | 9 +++ 8 files changed, 147 insertions(+), 7 deletions(-) create mode 100755 scripts/test-vue-policy.sh create mode 100644 tests/vue-consumer/Fixtures/ListItems.vue.fixture create mode 100644 tests/vue-consumer/Fixtures/eslint.config.mjs.fixture create mode 100644 tests/vue-consumer/Fixtures/package.json.fixture create mode 100644 tests/vue-consumer/qlty.toml.template diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1fd8904..5d3d54b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 # ========================================================================== diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9549210..3617d70 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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--policy.sh # Qlty consumer integration test for knip, shared, swift, terraform, trivy or zizmor +bash scripts/test--policy.sh # Qlty consumer integration test for knip, shared, swift, terraform, trivy, vue or zizmor ``` Single test file or method: diff --git a/README.md b/README.md index d22eace..ef06d21 100644 --- a/README.md +++ b/README.md @@ -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`: @@ -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--policy.sh # exported policy integration tests (knip, shared, swift, terraform, trivy, zizmor) +bash scripts/test--policy.sh # exported policy integration tests (knip, shared, swift, terraform, trivy, vue, zizmor) ``` The Swift policy test needs macOS. diff --git a/scripts/test-vue-policy.sh b/scripts/test-vue-policy.sh new file mode 100755 index 0000000..8dfb95a --- /dev/null +++ b/scripts/test-vue-policy.sh @@ -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 diff --git a/tests/vue-consumer/Fixtures/ListItems.vue.fixture b/tests/vue-consumer/Fixtures/ListItems.vue.fixture new file mode 100644 index 0000000..47f9085 --- /dev/null +++ b/tests/vue-consumer/Fixtures/ListItems.vue.fixture @@ -0,0 +1,3 @@ + diff --git a/tests/vue-consumer/Fixtures/eslint.config.mjs.fixture b/tests/vue-consumer/Fixtures/eslint.config.mjs.fixture new file mode 100644 index 0000000..c79c746 --- /dev/null +++ b/tests/vue-consumer/Fixtures/eslint.config.mjs.fixture @@ -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]; diff --git a/tests/vue-consumer/Fixtures/package.json.fixture b/tests/vue-consumer/Fixtures/package.json.fixture new file mode 100644 index 0000000..a671378 --- /dev/null +++ b/tests/vue-consumer/Fixtures/package.json.fixture @@ -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" + } +} diff --git a/tests/vue-consumer/qlty.toml.template b/tests/vue-consumer/qlty.toml.template new file mode 100644 index 0000000..a3226d4 --- /dev/null +++ b/tests/vue-consumer/qlty.toml.template @@ -0,0 +1,9 @@ +config_version = "0" + +[[source]] +name = "default" +default = true + +[[source]] +name = "sinemacula" +directory = "__SOURCE_DIRECTORY__"