prettier-plugin-gherkin
Advanced tools
Comparing version 1.0.0 to 1.1.0
# CHANGELOG | ||
## 1.1.0 | ||
- handle "language" comment | ||
- fix missing mediaType in json / xml embedded docstring | ||
- fix missing example description | ||
## 1.0.0 | ||
Version 1.0.0 is a complete rewrite of the [first version](https://github.com/armandabric/prettier-plugin-gherkin) by [@armandabric](https://github.com/armandabric). |
@@ -8,2 +8,4 @@ "use strict"; | ||
const DEFAULT_ESCAPE_BACKSLASH = false; | ||
// taken from https://github.com/cucumber/gherkin-javascript/blob/e25a1be3b21133c7a92eb7735997c6e774406226/src/GherkinClassicTokenMatcher.ts#L11 | ||
const LANGUAGE_PATTERN = /^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$/; | ||
const { literalline, hardline, join, group, trim, indent, line } = prettier_1.doc.builders; | ||
@@ -295,3 +297,7 @@ const { hasNewline, isPreviousLineEmpty, makeString } = prettier_1.util; | ||
else if (node instanceof GherkinAST_1.TypedFeature || node instanceof GherkinAST_1.TypedRule) { | ||
const hasLanguageInSourceFile = !!options.originalText.match(new RegExp(LANGUAGE_PATTERN, 'm')); | ||
return [ | ||
node instanceof GherkinAST_1.TypedFeature && hasLanguageInSourceFile | ||
? ['# language: ' + node.language, printHardline()] | ||
: '', | ||
printTags(path, node), | ||
@@ -395,3 +401,3 @@ `${node.keyword}: ${node.name}`, | ||
return join(printHardline(), [ | ||
`${node.delimiter}${node.mediaType || ''}`, | ||
[node.delimiter, node.mediaType || ''], | ||
// split the string on newlines to preserve the indentation | ||
@@ -409,2 +415,3 @@ ...escapeDelimiter(node.content).split('\n'), | ||
printHardline(), | ||
printDescription(path, node, false), | ||
join(printHardline(), [ | ||
@@ -451,2 +458,3 @@ // @ts-expect-error TODO path should be recognized as an AstPath<TypedExamples> | ||
node.delimiter, | ||
mediaType, | ||
printHardline(), | ||
@@ -461,2 +469,3 @@ textToDoc(content, Object.assign(Object.assign({}, options), { parser: 'html' })), | ||
node.delimiter, | ||
mediaType !== null && mediaType !== void 0 ? mediaType : '', | ||
printHardline(), | ||
@@ -463,0 +472,0 @@ textToDoc(content, Object.assign(Object.assign({}, options), { parser: 'json' })), |
{ | ||
"name": "prettier-plugin-gherkin", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "This prettier plugin format your gherkin (`.feature` files) documents.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -51,2 +51,5 @@ import { | ||
// taken from https://github.com/cucumber/gherkin-javascript/blob/e25a1be3b21133c7a92eb7735997c6e774406226/src/GherkinClassicTokenMatcher.ts#L11 | ||
const LANGUAGE_PATTERN = /^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$/; | ||
const { literalline, hardline, join, group, trim, indent, line } = doc.builders; | ||
@@ -470,3 +473,10 @@ const { hasNewline, isPreviousLineEmpty, makeString } = util; | ||
} else if (node instanceof TypedFeature || node instanceof TypedRule) { | ||
const hasLanguageInSourceFile = !!options.originalText.match( | ||
new RegExp(LANGUAGE_PATTERN, 'm') | ||
); | ||
return [ | ||
node instanceof TypedFeature && hasLanguageInSourceFile | ||
? ['# language: ' + node.language, printHardline()] | ||
: '', | ||
printTags(path, node), | ||
@@ -580,3 +590,3 @@ `${node.keyword}: ${node.name}`, | ||
return join(printHardline(), [ | ||
`${node.delimiter}${node.mediaType || ''}`, | ||
[node.delimiter, node.mediaType || ''], | ||
// split the string on newlines to preserve the indentation | ||
@@ -591,7 +601,7 @@ ...escapeDelimiter(node.content).split('\n'), | ||
printTags(path, node), | ||
`${node.keyword}: ${node.name}`, | ||
`${node.keyword}: ${node.name}`, | ||
indent([ | ||
printHardline(), | ||
printDescription(path, node, false), | ||
join( | ||
@@ -640,2 +650,3 @@ printHardline(), | ||
node.delimiter, | ||
mediaType, | ||
printHardline(), | ||
@@ -652,2 +663,3 @@ textToDoc(content, { ...options, parser: 'html' }), | ||
node.delimiter, | ||
mediaType ?? '', | ||
printHardline(), | ||
@@ -654,0 +666,0 @@ textToDoc(content, { ...options, parser: 'json' }), |
@@ -50,2 +50,4 @@ // source: https://github.com/prettier/prettier/blob/ee2839bacbf6a52d004fa2f0373b732f6f191ccc/tests_config/run_spec.js | ||
).toMatchSnapshot(); | ||
// expect(input.replace(/\s/g, '')).toBe(output.replace(/\s/g, '')); | ||
}); | ||
@@ -52,0 +54,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
272529
2030
0