Skip to content

Commit f7d1c15

Browse files
committed
auto-generated known files list
1 parent 7aae9b9 commit f7d1c15

File tree

18 files changed

+2265
-74
lines changed

18 files changed

+2265
-74
lines changed

.github/workflows/go.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ jobs:
5555
- name: Check Formatting
5656
run: test -z "$(gofmt -s -l -e .)"
5757

58+
- name: Check generated files are up to date
59+
run: |
60+
go generate ./pkg/filetype/...
61+
git diff --exit-code pkg/filetype/known_files_gen.go
62+
5863
build:
5964
needs: download
6065
runs-on: ubuntu-latest
@@ -71,6 +76,9 @@ jobs:
7176
with:
7277
go-version: "1.26"
7378

79+
- name: Generate known files from Linguist
80+
run: go generate ./pkg/filetype/...
81+
7482
- name: Build
7583
run: |
7684
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Automatic file type detection from GitHub Linguist's `languages.yml` via `go generate`
13+
- ~90 known filenames auto-detected (`.babelrc`, `tsconfig.json`, `Pipfile`, `pom.xml`, `.gitconfig`, etc.)
14+
- SchemaStore now resolves schemas for extensionless known files (`.babelrc`, `.clangd`, etc.)
15+
- JSON and JSONC treated as a family for `--file-types` and `--exclude-file-types`
16+
- `go generate` step in CI pipeline to keep Linguist data fresh
17+
- CI lint check to ensure generated files are committed up to date
18+
19+
### Fixed
20+
21+
- KnownFiles now take priority over extension matching in the finder, so `tsconfig.json` resolves to JSONC (not JSON)
22+
- Extension exclusion cache no longer prevents known files from being found
23+
- Linguist known files that conflict with dedicated validators are automatically excluded (e.g. `.editorconfig` stays with EditorConfig, not INI)
24+
825
## [2.2.0] - 2026-04-10
926

1027
### Changed

cmd/validator/testdata/configfile.txtar

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ stderr 'schema validation failed'
3636
! exec validator --config=cfv/bad_syntax.toml project/good.json
3737
stderr 'invalid TOML syntax'
3838

39-
# --no-config ignores config file (tsconfig fails as strict JSON)
40-
! exec validator --no-config project/tsconfig.json
41-
stdout '×'
39+
# --no-config ignores config file (type-map not applied, custom.cfg not recognized)
40+
exec validator --no-config project/custom.cfg
41+
! stdout 'custom.cfg'
42+
43+
# With config file, custom.cfg is recognized as JSON via type-map
44+
exec validator --config=cfv/typemap.toml project/custom.cfg
45+
stdout '✓'
4246

4347
-- cfv/typemap.toml --
4448
[type-map]
4549
"**/tsconfig.json" = "jsonc"
50+
"**/custom.cfg" = "json"
4651

4752
-- cfv/excludedir.toml --
4853
exclude-dirs = ["excluded"]
@@ -84,3 +89,6 @@ quiet = [broken
8489

8590
-- project/sub/nested.json --
8691
{"key": "value"}
92+
93+
-- project/custom.cfg --
94+
{"key": "value"}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# ============================================================
2+
# Functional tests for Linguist known files
3+
# Verifies that extensionless files are auto-detected by type
4+
# ============================================================
5+
6+
# YAML known files
7+
exec validator .clang-format
8+
stdout '✓'
9+
10+
exec validator .clang-tidy
11+
stdout '✓'
12+
13+
exec validator .clangd
14+
stdout '✓'
15+
16+
exec validator .gemrc
17+
stdout '✓'
18+
19+
# INI known files
20+
exec validator .gitconfig
21+
stdout '✓'
22+
23+
exec validator .npmrc
24+
stdout '✓'
25+
26+
exec validator .shellcheckrc
27+
stdout '✓'
28+
29+
# JSON known files
30+
exec validator .arcconfig
31+
stdout '✓'
32+
33+
exec validator composer.lock
34+
stdout '✓'
35+
36+
# JSONC known files
37+
exec validator .babelrc
38+
stdout '✓'
39+
40+
exec validator tsconfig.json
41+
stdout '✓'
42+
43+
# TOML known files
44+
exec validator Pipfile
45+
stdout '✓'
46+
47+
# XML known files
48+
exec validator pom.xml
49+
stdout '✓'
50+
51+
# Invalid known files should fail
52+
! exec validator invalid/.clang-format
53+
stdout '×'
54+
55+
! exec validator invalid/.babelrc
56+
stdout '×'
57+
58+
# Unknown extensionless files should be ignored (exit 0, no output)
59+
exec validator unknown
60+
! stdout '.'
61+
62+
# ============================================================
63+
# SchemaStore with extensionless known files
64+
# ============================================================
65+
66+
# .babelrc valid against schema
67+
exec validator --schemastore-path schemastore .babelrc
68+
stdout '✓'
69+
70+
# .babelrc invalid against schema (additionalProperties: false)
71+
! exec validator --schemastore-path schemastore invalid-schema/.babelrc
72+
stdout '×'
73+
stdout 'error:'
74+
75+
# .clangd valid against schema
76+
exec validator --schemastore-path schemastore .clangd
77+
stdout '✓'
78+
79+
# ============================================================
80+
# Valid known files
81+
# ============================================================
82+
83+
-- .clang-format --
84+
BasedOnStyle: LLVM
85+
IndentWidth: 4
86+
-- .clang-tidy --
87+
Checks: '-*,readability-*'
88+
-- .clangd --
89+
CompileFlags:
90+
Add: [-Wall]
91+
-- .gemrc --
92+
gem: --no-document
93+
-- .gitconfig --
94+
[user]
95+
name=test
96+
email=test@example.com
97+
-- .npmrc --
98+
registry=https://registry.npmjs.org/
99+
-- .shellcheckrc --
100+
disable=SC2034
101+
-- .arcconfig --
102+
{"project_id": "myproject"}
103+
-- composer.lock --
104+
{"packages": [], "_readme": ["This file locks the dependencies"]}
105+
-- .babelrc --
106+
{"presets": ["env"]}
107+
-- tsconfig.json --
108+
// TypeScript config
109+
{"compilerOptions": {"strict": true}}
110+
-- Pipfile --
111+
[packages]
112+
requests = "*"
113+
-- pom.xml --
114+
<project><modelVersion>4.0.0</modelVersion></project>
115+
-- unknown --
116+
this is not a config file
117+
118+
# ============================================================
119+
# Invalid known files
120+
# ============================================================
121+
122+
-- invalid/.clang-format --
123+
BasedOnStyle: LLVM
124+
bad indentation:
125+
- this: is broken
126+
::::::
127+
-- invalid/.babelrc --
128+
{"bad": }
129+
130+
# ============================================================
131+
# SchemaStore invalid files
132+
# ============================================================
133+
134+
-- invalid-schema/.babelrc --
135+
{"presets": ["env"], "unknown_field": true}
136+
137+
# ============================================================
138+
# Mini SchemaStore bundle with extensionless entries
139+
# ============================================================
140+
141+
-- schemastore/src/api/json/catalog.json --
142+
{
143+
"schemas": [
144+
{
145+
"name": "Babel",
146+
"fileMatch": [".babelrc"],
147+
"url": "https://www.schemastore.org/babelrc.json"
148+
},
149+
{
150+
"name": "clangd",
151+
"fileMatch": [".clangd"],
152+
"url": "https://www.schemastore.org/clangd.json"
153+
}
154+
]
155+
}
156+
-- schemastore/src/schemas/json/babelrc.json --
157+
{
158+
"type": "object",
159+
"properties": {
160+
"presets": { "type": "array", "items": { "type": "string" } },
161+
"plugins": { "type": "array" }
162+
},
163+
"additionalProperties": false
164+
}
165+
-- schemastore/src/schemas/json/clangd.json --
166+
{
167+
"type": "object",
168+
"properties": {
169+
"CompileFlags": { "type": "object" },
170+
"Diagnostics": { "type": "object" },
171+
"InlayHints": { "type": "object" }
172+
}
173+
}

0 commit comments

Comments
 (0)