-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { defineRule } from './util' | ||
|
||
export default function RuleNoUppercaseChars() { | ||
return defineRule({ | ||
id: 'no-uppercase-chars', | ||
test({ report, link }) { | ||
if (link.match(/[A-Z]/)) { | ||
report({ | ||
name: 'no-uppercase-chars', | ||
scope: 'warning', | ||
message: 'Links should not contain uppercase characters.', | ||
fix: link.toLowerCase(), | ||
fixDescription: 'Convert to lowercase.', | ||
}) | ||
} | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { RuleTestContext } from '../../../src/runtime/types' | ||
import { describe, expect, it } from 'vitest' | ||
import RuleNoUppercaseChars from '../../../src/runtime/shared/inspections/no-uppercase-chars' | ||
import { runRule } from './util' | ||
|
||
describe('rule no-uppercase-chars', () => { | ||
it('works', () => { | ||
expect(runRule({ link: 'https://example.com/PAGE' } as RuleTestContext, RuleNoUppercaseChars())).toMatchInlineSnapshot(` | ||
{ | ||
"error": [], | ||
"fix": "https://example.com/page", | ||
"link": "https://example.com/PAGE", | ||
"passes": false, | ||
"textContent": undefined, | ||
"warning": [ | ||
{ | ||
"fix": "https://example.com/page", | ||
"fixDescription": "Convert to lowercase.", | ||
"message": "Links should not contain uppercase characters.", | ||
"name": "no-uppercase-chars", | ||
"scope": "warning", | ||
}, | ||
], | ||
} | ||
`) | ||
|
||
expect(runRule({ link: '/this/IS/a/TEEST' } as RuleTestContext, RuleNoUppercaseChars())).toMatchInlineSnapshot(` | ||
{ | ||
"error": [], | ||
"fix": "/this/is/a/teest", | ||
"link": "/this/IS/a/TEEST", | ||
"passes": false, | ||
"textContent": undefined, | ||
"warning": [ | ||
{ | ||
"fix": "/this/is/a/teest", | ||
"fixDescription": "Convert to lowercase.", | ||
"message": "Links should not contain uppercase characters.", | ||
"name": "no-uppercase-chars", | ||
"scope": "warning", | ||
}, | ||
], | ||
} | ||
`) | ||
}) | ||
}) |
7e92daf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harlan-zw what do you think about running this check on internal links only by default? External links and how external services treat casing are not really under the developer's control, so warning about this might add much noise, I think.
7e92daf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm we there's many rules like this we shouldn't run on external links so this is a bug that should be fixed
7e92daf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed in 4.0.2