Skip to content
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

Add check for Windows-forbidden characters in the filename #353

Merged
merged 29 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8e176be
Update tldr-lint.js
sebastiaanspeck Sep 29, 2024
85d8b6a
Update README.md
sebastiaanspeck Sep 29, 2024
1858f95
Update tldr-lint.js
sebastiaanspeck Sep 29, 2024
e28c935
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
0c51bc8
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
c9b970f
Create 111<.md
sebastiaanspeck Sep 29, 2024
1e082e0
Delete specs/pages/failing/111<.md
sebastiaanspeck Sep 29, 2024
7ecbb9c
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
6eef7c6
Update package.json
sebastiaanspeck Sep 29, 2024
c91cc73
Update package.json
sebastiaanspeck Sep 29, 2024
ec50a9c
fix-up package-lock.json
sebastiaanspeck Sep 29, 2024
c8e7418
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
000a3c5
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
9a1f8c1
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
f63624a
Create 111.md
sebastiaanspeck Sep 29, 2024
41eeedb
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
abc4f1d
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
98719ac
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
09810a8
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
dacc2af
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
39745f6
Update package-lock.json
sebastiaanspeck Sep 29, 2024
5ffcca6
Update package.json
sebastiaanspeck Sep 29, 2024
52a6ec6
eslint
sebastiaanspeck Sep 29, 2024
02568e8
Update tldr-lint.js
sebastiaanspeck Sep 29, 2024
a77c2de
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
7bd452f
Update tldr-lint.spec.js
sebastiaanspeck Sep 29, 2024
aadc03f
Update tldr-lint.js
sebastiaanspeck Sep 29, 2024
0c107bb
Merge branch 'main' into feature/windows-illegal-chars
sebastiaanspeck Oct 3, 2024
c125c42
Update CHANGELOG.md
sebastiaanspeck Oct 4, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com).

## Unreleased

- Add rule `TLDR111` ([#353](https://github.com/tldr-pages/tldr-lint/pull/353))

## [v0.0.15 - 2024-04-03](https://github.com/tldr-pages/tldr-lint/compare/v0.0.14...v0.0.15)

- Add rule `TLDR020` ([#308](https://github.com/tldr-pages/tldr-lint/pull/308))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ TLDR107 | File name should end with `.md` extension
TLDR108 | File name should not contain whitespace
TLDR109 | File name should be lowercase
TLDR110 | Command example should not be empty
TLDR111 | File name should not contain any Windows-forbidden character

[npm-url]: https://www.npmjs.com/package/tldr-lint
[npm-image]: https://img.shields.io/npm/v/tldr-lint.svg
Expand Down
5 changes: 5 additions & 0 deletions lib/tldr-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports.ERRORS = parser.ERRORS = {
'TLDR108': 'File name should not contain whitespace',
'TLDR109': 'File name should be lowercase',
'TLDR110': 'Command example should not be empty',
'TLDR111': 'File name should not contain any Windows-forbidden character'
};

(function(parser) {
Expand Down Expand Up @@ -212,6 +213,10 @@ linter.processFile = function(file, verbose, alsoFormat, ignoreErrors) {
result.errors.push({ locinfo: { first_line: '0' }, code: 'TLDR109', description: this.ERRORS.TLDR109 });
}

if (/[<>:"/\\|?*]/.test(path.basename(file))) {
result.errors.push({ locinfo: { first_line: '0' }, code: 'TLDR111', description: this.ERRORS.TLDR111 });
}

if (ignoreErrors) {
ignoreErrors = ignoreErrors.split(',').map(function(val) {
return val.trim();
Expand Down
7 changes: 7 additions & 0 deletions specs/pages/failing/111.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# jar

> JAR (Java Archive) is a package file format.

- Unzip file to the current directory:

`jar -xvf *.jar`
16 changes: 16 additions & 0 deletions specs/tldr-lint.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const linter = require('../lib/tldr-lint.js');
const { lintFile, containsErrors, containsOnlyErrors } = require('./tldr-lint-helper');

Expand Down Expand Up @@ -183,6 +184,21 @@ describe('Common TLDR formatting errors', function() {
expect(containsOnlyErrors(errors, 'TLDR110')).toBeTruthy();
expect(errors.length).toBe(1);
});

const invalidCharacters = ['<', '>', ':', '"', '/', '\\', '|', '?', '*'];
invalidCharacters.forEach((char) => {
it('TLDR111\t' + linter.ERRORS.TLDR111 + '\t - ${char}', function() {
const basenameSpy = jest.spyOn(path, 'basename').mockImplementation((filePath) => {
return `111${char}`;
});

let errors = lintFile(`pages/failing/111.md`).errors;
expect(containsOnlyErrors(errors, 'TLDR111')).toBeTruthy();
expect(errors.length).toBe(1);

basenameSpy.mockRestore();
});
});
});

describe('TLDR pages that are simply correct', function() {
Expand Down