Skip to content

Commit

Permalink
fix: Ignore hash links like [abcdefa] (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed May 30, 2021
1 parent d87aa65 commit 888e25d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
"CStyleHexValue",
"CSSHexValue",
"CommitHash",
"CommitHashLink",
"Email",
"EscapeCharacters",
"HexValues",
Expand Down
4 changes: 3 additions & 1 deletion packages/cspell-lib/src/Settings/DefaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const regExpSpellCheckerDisable = [
const predefinedPatterns = [
// Exclude patterns
{ name: 'CommitHash', pattern: RegPat.regExCommitHash },
{ name: 'CommitHashLink', pattern: RegPat.regExCommitHashLink },
{ name: 'CStyleHexValue', pattern: RegPat.regExCStyleHexValue },
{ name: 'CSSHexValue', pattern: RegPat.regExCSSHexValue },
{ name: 'Urls', pattern: RegPat.regExMatchUrls },
Expand Down Expand Up @@ -68,6 +69,7 @@ const definedDefaultRegExpExcludeList: PredefinedPatterns[] = [
'RsaCert',
'Base64',
'CommitHash',
'CommitHashLink',
'CStyleHexValue',
'CSSHexValue',
'SHA',
Expand All @@ -78,7 +80,7 @@ const definedDefaultRegExpExcludeList: PredefinedPatterns[] = [
// This bit of copying is done to have the complier ensure that the defaults exist.
const defaultRegExpExcludeList: PredefinedPatternNames[] = definedDefaultRegExpExcludeList;

export const _defaultSettings: CSpellSettingsWithSourceTrace = {
export const _defaultSettings: Readonly<CSpellSettingsWithSourceTrace> = {
id: 'static_defaults',
language: 'en',
name: 'Static Defaults',
Expand Down
16 changes: 16 additions & 0 deletions packages/cspell-lib/src/Settings/RegExpPatterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ describe('Validate InDocSettings', () => {
expect(r?.[0]).toEqual(expected);
});

test.each`
str | expected | comment
${''} | ${undefined} | ${''}
${'hello'} | ${undefined} | ${''}
${'commit [60975ea] j'} | ${'[60975ea]'} | ${''}
${'commit [c0ffee] j'} | ${undefined} | ${'not long enough'}
${'commit [abcdef] j'} | ${undefined} | ${'not long enough'}
${'commit [abcdefg] j'} | ${undefined} | ${'contains non-hex digits'}
${'commit [c00ffee] j'} | ${'[c00ffee]'} | ${''}
${'commit [feeeeed] j'} | ${'[feeeeed]'} | ${'does not contain any digits'}
${'commit [feeeeed1] j'} | ${'[feeeeed1]'} | ${''}
${'commit [c00ffee] 0baad j'} | ${'[c00ffee]'} | ${'only the first one is matched'}
`('regExCommitHashLink "$str" expect "$expected"', ({ str, expected }) => {
const r = str.match(RegPat.regExCommitHashLink);
expect(r?.[0]).toEqual(expected);
});
test.each`
str | expected
${''} | ${undefined}
Expand Down
1 change: 1 addition & 0 deletions packages/cspell-lib/src/Settings/RegExpPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const regExHRef = /\bhref\s*=\s*".*?"/gi;
export const regExMatchCommonHexFormats =
/(?:#[0-9a-f]{3,8})|(?:0x[0-9a-f]+)|(?:\\u[0-9a-f]{4})|(?:\\x\{[0-9a-f]{4}\})/gi;
export const regExCommitHash = /\b(?![a-f]+\b)(?:0x)?[0-9a-f]{7,}\b/gi; // Match Commit Hashes that contain at least one digit.
export const regExCommitHashLink = /\[[0-9a-f]{7,}\]/gi; // Match Commit Hash Markdown link: [abcdef0].
export const regExCStyleHexValue = /\b0x[0-9a-f]+\b/gi;
export const regExCSSHexValue = /#[0-9a-f]{3,8}\b/gi;
export const regExUUID = /\b[0-9a-fx]{8}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{12}\b/gi; // x - represents placeholder values
Expand Down
1 change: 1 addition & 0 deletions packages/cspell-types/cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
"CStyleHexValue",
"CSSHexValue",
"CommitHash",
"CommitHashLink",
"Email",
"EscapeCharacters",
"HexValues",
Expand Down
1 change: 1 addition & 0 deletions packages/cspell-types/src/settings/CSpellSettingsDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export type PredefinedPatterns =
| 'CStyleHexValue'
| 'CSSHexValue'
| 'CommitHash'
| 'CommitHashLink'
| 'Email'
| 'EscapeCharacters'
| 'HexValues'
Expand Down

0 comments on commit 888e25d

Please sign in to comment.