-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
warn for ambiguous colons in formats (#2335)
- Loading branch information
1 parent
c1784c4
commit 7110de3
Showing
11 changed files
with
156 additions
and
71 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
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
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
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
This file was deleted.
Oops, something went wrong.
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,80 @@ | ||
import { ILogger } from '../logger' | ||
|
||
export function splitFormatDescriptor( | ||
logger: ILogger, | ||
option: string | ||
): string[] { | ||
const doWarning = (result: string[]) => { | ||
let expected = `"${result[0]}"` | ||
if (result[1]) { | ||
expected += `:"${result[1]}"` | ||
} | ||
logger.warn( | ||
`Each part of a user-specified format should be quoted; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md#ambiguous-colons-in-formats | ||
Change to ${expected}` | ||
) | ||
} | ||
let result: string[] | ||
let match1, match2 | ||
|
||
// "foo":"bar" or "foo":bar | ||
if ((match1 = option.match(/^"([^"]*)":(.*)$/)) !== null) { | ||
// "foo":"bar" | ||
if ((match2 = match1[2].match(/^"([^"]*)"$/)) !== null) { | ||
result = [match1[1], match2[1]] | ||
} | ||
// "foo":bar | ||
else { | ||
result = [match1[1], match1[2]] | ||
if (result[1].includes(':')) { | ||
doWarning(result) | ||
} | ||
} | ||
} | ||
// foo:"bar" | ||
else if ((match1 = option.match(/^(.*):"([^"]*)"$/)) !== null) { | ||
result = [match1[1], match1[2]] | ||
if (result[0].includes(':')) { | ||
doWarning(result) | ||
} | ||
} | ||
// "foo" | ||
else if ((match1 = option.match(/^"([^"]*)"$/)) !== null) { | ||
result = [match1[1], ''] | ||
} | ||
// file://foo or file:///foo or file://C:/foo or file://C:\foo or file:///C:/foo or file:///C:\foo | ||
else if ( | ||
(match1 = option.match(/^(file:\/{2,3}(?:[a-zA-Z]:[/\\])?)(.*)$/)) !== null | ||
) { | ||
// file://foo:bar | ||
if ((match2 = match1[2].match(/^([^:]*):(.*)$/)) !== null) { | ||
result = [match1[1] + match2[1], match2[2]] | ||
} else { | ||
result = [option, ''] | ||
} | ||
doWarning(result) | ||
} | ||
// C:\foo or C:/foo | ||
else if ((match1 = option.match(/^([a-zA-Z]:[/\\])(.*)$/)) !== null) { | ||
// C:\foo:bar or C:/foo:bar | ||
if ((match2 = match1[2].match(/^([^:]*):(.*)$/)) !== null) { | ||
result = [match1[1] + match2[1], match2[2]] | ||
} else { | ||
result = [option, ''] | ||
} | ||
doWarning(result) | ||
} | ||
// foo:bar | ||
else if ((match1 = option.match(/^([^:]*):(.*)$/)) !== null) { | ||
result = [match1[1], match1[2]] | ||
if (option.split(':').length > 2) { | ||
doWarning(result) | ||
} | ||
} | ||
// foo | ||
else { | ||
result = [option, ''] | ||
} | ||
|
||
return result | ||
} |
Oops, something went wrong.