prettier-plugin-gherkin
Advanced tools
Comparing version 2.2.0 to 2.2.1
# CHANGELOG | ||
## [2.2.1] - 2023-12-28 | ||
- Fix new lines between two comments line [#17](https://github.com/mapado/prettier-plugin-gherkin/pull/17) by [@jdeniau](https://github.com/jdeniau) | ||
- Fix new line for comments in data tables [#18](https://github.com/mapado/prettier-plugin-gherkin/pull/18) by [@jdeniau](https://github.com/jdeniau) | ||
## [2.2.0] - 2023-12-28 | ||
@@ -4,0 +9,0 @@ |
@@ -203,6 +203,4 @@ export function isWithLocation(node) { | ||
get lastLine() { | ||
const dataTableLength = this.dataTable?.rows.length ?? 0; | ||
const docStringLength = this.docString | ||
? this.docString.content.split('\n').length + 2 | ||
: 0; | ||
const dataTableLength = this.dataTable?.nbRows ?? 0; | ||
const docStringLength = this.docString?.nbRows ?? 0; | ||
return this.location.line + dataTableLength + docStringLength; | ||
@@ -300,2 +298,5 @@ } | ||
} | ||
get nbRows() { | ||
return this.content.split('\n').length + 2; | ||
} | ||
} | ||
@@ -309,2 +310,9 @@ export class TypedDataTable extends TypedGherkinNodeWithLocation { | ||
} | ||
get nbRows() { | ||
return (this.rows.reduce((acc, row) => { | ||
// @ts-expect-error comments are added by prettier directly | ||
const commentLines = row.comments?.length ?? 0; | ||
return acc + commentLines + 1; | ||
}, 0) ?? 0); | ||
} | ||
get children() { | ||
@@ -311,0 +319,0 @@ return this.rows; |
@@ -178,3 +178,3 @@ import { Parser as GherkinParser, AstBuilder, GherkinClassicTokenMatcher, } from '@cucumber/gherkin'; | ||
} | ||
function stepNeedsHardline(options, node, commentNode, previousNode) { | ||
function stepNeedsHardline(options, node, previousNode) { | ||
if (!previousNode) { | ||
@@ -184,5 +184,9 @@ // do not force hardline for the first step | ||
} | ||
const currentNode = commentNode ?? node; | ||
const currentNode = node; | ||
if (options.forceNewlineBetweenStepBlocks !== true) { | ||
const hadHardlineBefore = previousNode && currentNode.location.line - previousNode.lastLine >= 2; | ||
// @ts-expect-error comments are injected by prettier directly | ||
const commentNodes = node.comments ?? []; | ||
const hadHardlineBefore = previousNode && | ||
currentNode.location.line - commentNodes.length - previousNode.lastLine >= | ||
2; | ||
if (hadHardlineBefore) { | ||
@@ -208,3 +212,3 @@ return true; | ||
if (stepNode instanceof TypedStep && | ||
stepNeedsHardline(options, stepNode, node, previousNode)) { | ||
stepNeedsHardline(options, stepNode, previousNode)) { | ||
return [printHardline(), node.text.trim()]; | ||
@@ -356,3 +360,3 @@ } | ||
// if the step has comment, the hardline will be handled by the comment printer | ||
stepNeedsHardline(options, node, null, previousNode) && | ||
stepNeedsHardline(options, node, previousNode) && | ||
// @ts-expect-error comments are injected by prettier directly | ||
@@ -359,0 +363,0 @@ !node.comments |
{ | ||
"name": "prettier-plugin-gherkin", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "This prettier plugin format your gherkin (`.feature` files) documents.", |
@@ -334,6 +334,4 @@ import { | ||
get lastLine(): number { | ||
const dataTableLength = this.dataTable?.rows.length ?? 0; | ||
const docStringLength = this.docString | ||
? this.docString.content.split('\n').length + 2 | ||
: 0; | ||
const dataTableLength = this.dataTable?.nbRows ?? 0; | ||
const docStringLength = this.docString?.nbRows ?? 0; | ||
@@ -473,2 +471,6 @@ return this.location.line + dataTableLength + docStringLength; | ||
} | ||
get nbRows(): number { | ||
return this.content.split('\n').length + 2; | ||
} | ||
} | ||
@@ -490,2 +492,13 @@ | ||
get nbRows(): number { | ||
return ( | ||
this.rows.reduce((acc, row) => { | ||
// @ts-expect-error comments are added by prettier directly | ||
const commentLines: number = row.comments?.length ?? 0; | ||
return acc + commentLines + 1; | ||
}, 0) ?? 0 | ||
); | ||
} | ||
get children(): ReadonlyArray<TypedTableRow> { | ||
@@ -492,0 +505,0 @@ return this.rows; |
@@ -316,3 +316,2 @@ import { | ||
node: TypedStep, | ||
commentNode: null | TypedComment, | ||
previousNode: null | TypedStep | ||
@@ -325,7 +324,12 @@ ) { | ||
const currentNode = commentNode ?? node; | ||
const currentNode = node; | ||
if (options.forceNewlineBetweenStepBlocks !== true) { | ||
// @ts-expect-error comments are injected by prettier directly | ||
const commentNodes = node.comments ?? []; | ||
const hadHardlineBefore = | ||
previousNode && currentNode.location.line - previousNode.lastLine >= 2; | ||
previousNode && | ||
currentNode.location.line - commentNodes.length - previousNode.lastLine >= | ||
2; | ||
@@ -361,3 +365,3 @@ if (hadHardlineBefore) { | ||
stepNode instanceof TypedStep && | ||
stepNeedsHardline(options, stepNode, node, previousNode) | ||
stepNeedsHardline(options, stepNode, previousNode) | ||
) { | ||
@@ -552,3 +556,3 @@ return [printHardline(), node.text.trim()]; | ||
// if the step has comment, the hardline will be handled by the comment printer | ||
stepNeedsHardline(options, node, null, previousNode) && | ||
stepNeedsHardline(options, node, previousNode) && | ||
// @ts-expect-error comments are injected by prettier directly | ||
@@ -555,0 +559,0 @@ !node.comments |
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
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
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
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
18909180
763
149397