mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-01 04:13:55 +01:00
Design lint prints missing paths relative to your folder, also through symlinks (#4859)
`gstack-design-lint` now names a file it cannot read relative to the folder you ran it from, even when that file sits under a symlinked folder (on macOS, anything under `/tmp` or `/var`). Before, it printed the full absolute path. The design-lint tests pass on a Mac again. Rebuilt from #4856 by Akkyman2, with thanks. Nothing to do. Co-authored-by: Akkyman2 <178076175+Akkyman2@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
4 files changed
+21
-6
No files matched your search
@@ -87,11 +87,18 @@ describe('design-lint fifth cycle: dead markup and hostile inputs', () => {
|
||||
expect(resolveRef('../outside.css', path.join(dir, 'site'), path.join(dir, 'site'))).toBeNull();
|
||||
});
|
||||
|
||||
test('an unreadable top-level path beside a readable page is one internal-error finding with its own fix', () => {
|
||||
// Value: protects=an unreadable top-level path prints relative to a cwd reached through a symlink; fails_when=the finding keeps the unresolved path while cwd is resolved; why_new=only a symlinked tmpdir (macOS) hit it; seam=none
|
||||
test('an unreadable top-level path beside a readable page is one internal-error finding with its own fix, also through a symlink', () => {
|
||||
const dir = tree({ 'index.html': page('', '<main><h1>Hi</h1><p>Body.</p></main>') });
|
||||
const r = lintStatic([dir, path.join(dir, 'nowhere.html')], { cwd: dir, ...quiet });
|
||||
expect(r.files.map((f) => path.basename(f))).toEqual(['index.html']);
|
||||
expect(only(r.findings, 'internal-error').map((f) => [f.grade, f.file, f.line, /cannot be read/.test(f.evidence), f.fix])).toEqual([['ask', 'nowhere.html', 1, true, 'check the path']]);
|
||||
const link = dir + '-link';
|
||||
fs.symlinkSync(dir, link);
|
||||
tmpDirs.push(link);
|
||||
fs.symlinkSync(path.join(dir, 'self'), path.join(dir, 'self'));
|
||||
const via = lintStatic([link, path.join(link, 'gone', 'nowhere.html'), path.join(link, 'self')], { cwd: link, ...quiet });
|
||||
expect(only(via.findings, 'internal-error').map((f) => f.file)).toEqual([path.join('gone', 'nowhere.html'), 'self']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ function tmpPage(html: string, name = 'index.html'): string {
|
||||
return file;
|
||||
}
|
||||
|
||||
/** A temporary tree: each key is a relative path (parent directories are created), each value the file's text. */
|
||||
/** A temporary tree: each key is a relative path (parent directories are created), each value the file's text. Its root is the real path, as the lint walks real paths. */
|
||||
function tmpTree(files: Record<string, string>): string {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'design-lint-tree-'));
|
||||
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'design-lint-tree-')));
|
||||
tmpDirs.push(dir);
|
||||
for (const [rel, text] of Object.entries(files)) {
|
||||
fs.mkdirSync(path.dirname(path.join(dir, rel)), { recursive: true });
|
||||
|
||||
Reference in new issue
Block a user