martin-helmich / typo3-typoscript-lint

Find coding errors in your TypoScript files.
MIT License
82 stars 19 forks source link

"Common path prefix" with ">" operator #122

Closed KamiYang closed 2 years ago

KamiYang commented 2 years ago

Hi everyone,

I just have a question about the "Common path prefix"-Sniff: While linting the following TypoScript the linter only warns about line 5 & 6 (bar.baz) but not about 2 & 3 (foo.baa).

Is this behaivor intended? And if so, why?

foo.typoscript

lib {
    foo.baa.10 >
    foo.baa.20 >

    bar.baz.10 = TEXT
    bar.baz.20 = TEXT
}

linter output

/usr/bin/php vendor/bin/typoscript-lint 
W                                                    [1 / 1, 100%]

Completed with 4 issues

CHECKSTYLE REPORT
=> test/foo.typoscript
   5 Common path prefix "bar" with assignment to "bar.baz.20" in line 6. Consider merging them into a nested assignment.
   5 Common path prefix "bar.baz" with assignment to "bar.baz.20" in line 6. Consider merging them into a nested assignment.
   6 Common path prefix "bar" with assignment to "bar.baz.10" in line 5. Consider merging them into a nested assignment.
   6 Common path prefix "bar.baz" with assignment to "bar.baz.10" in line 5. Consider merging them into a nested assignment.

SUMMARY
4 issues in total. (4 warnings)

KamiYang

martin-helmich commented 2 years ago

Thanks for the report -- I assume that the cause for this issue is that the NestingConsistencySniff explicitly looks for assignment statements, and not deletions or other statements that operate on an object path. It's been a while since I last touched that code, but I assume that this is most probably not intentional and more likely an oversight.

martin-helmich commented 2 years ago

Just verified this, by having a look in the NestingConsistencyVisitor class:

https://github.com/martin-helmich/typo3-typoscript-lint/blob/667eb63e1639b9fd726f72d1825be09ecfbdbb95/src/Linter/Sniff/Visitor/NestingConsistencyVisitor.php#L67

So, yes: The NestingConsistencySniff explicitly looks at assignment operations, and nothing else. I'll see if there's an easy fix for that.

Mabahe commented 1 year ago

Possible regression: https://github.com/martin-helmich/typo3-typoscript-lint/pull/124#issuecomment-1408779405