Skip to content

Conversation

@Marat-Tim
Copy link
Contributor

In this pull request, I’m adding a linter that checks whether an object can be merged with its parent. There were two potential approaches to implementing this: one involved identifying full chains of possible merges—for example, in the following code:

<o base=".foo">
  <o base=".bar">
    <o base="x" line="2"/>
  </o>
</o>

These objects could theoretically be merged into:

<o base="x.bar.foo"/>

However, such a search is relatively complex in terms of either memory usage or computational resources

I opted for a simpler approach, where in the above example, the linter will generate a warning like:
Object on line 2 can be merged with its parent

After performing the suggested merge and re-running the linter, another warning will appear, allowing the issue to be resolved over several iterations

@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2025

🚀 Performance Analysis

Test Base Score PR Score Change % Change Unit Mode
benchmarks.SourceBench.scansXmir (size=S) 4283.313 4470.818 187.506 4.38% ms/op Average Time
benchmarks.SourceBench.scansXmir (size=M) 4945.933 5021.179 75.246 1.52% ms/op Average Time
benchmarks.SourceBench.scansXmir (size=L) 5815.847 5830.155 14.308 0.25% ms/op Average Time
benchmarks.SourceBench.scansXmir (size=XL) 7252.064 7316.523 64.459 0.89% ms/op Average Time
benchmarks.SourceBench.scansXmir (size=XXL) 20143.619 20160.257 16.638 0.08% ms/op Average Time

⚠️ Performance loss: benchmarks.SourceBench.scansXmir (size=S) is slower by 187.506 ms/op (4.38%)
⚠️ Performance loss: benchmarks.SourceBench.scansXmir (size=M) is slower by 75.246 ms/op (1.52%)
⚠️ Performance loss: benchmarks.SourceBench.scansXmir (size=L) is slower by 14.308 ms/op (0.25%)
⚠️ Performance loss: benchmarks.SourceBench.scansXmir (size=XL) is slower by 64.459 ms/op (0.89%)
⚠️ Performance loss: benchmarks.SourceBench.scansXmir (size=XXL) is slower by 16.638 ms/op (0.08%)

@Marat-Tim
Copy link
Contributor Author

@maxonfjvipon


```xml
<o base="foo">
<o base=".bar"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marat-Tim such example is not correct because .bar method should be taken from some object. So you need to add a nested object that can't be merged with .bar or just remove dot: bar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon I forgot to delete this

<object>
<o base=".foo">
<o base="bar">
A1-B2-C3-D4-E5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marat-Tim there's something wrong with indentation here

<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[not(eo:abstract(.)) and parent::o[starts-with(@base, '.')] and not(starts-with(@base, '.')) and not(text())]">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marat-Tim actually it's pretty good, but I think you missed the one more condition - and not(o). You can add this test:

<o base=".foo">
  <o base="bar">
    <o base="baz"/>
  </o>
</o>

I believe with current approach you'll get a defect, but there's no one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon This is checked with not(text()) because if element has an inner object, text() returns its text content. I added this test

@Marat-Tim Marat-Tim requested a review from maxonfjvipon May 5, 2025 12:32
@Marat-Tim
Copy link
Contributor Author

@yegor256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants