-
Notifications
You must be signed in to change notification settings - Fork 19
feat(#556): auto-fix architecture #584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,9 @@ | |
| import org.cactoos.io.ResourceOf; | ||
| import org.cactoos.text.IoCheckedText; | ||
| import org.cactoos.text.TextOf; | ||
| import org.eolang.lints.fix.Edit; | ||
| import org.eolang.lints.fix.File; | ||
| import org.eolang.lints.fix.Fix; | ||
| import org.eolang.parser.ObjectName; | ||
|
|
||
| /** | ||
|
|
@@ -98,15 +101,26 @@ public Collection<Defect> defects(final XML xmir) { | |
| String.format("No severity reported by %s", this.rule) | ||
| ); | ||
| } | ||
| final Optional<String> message = xml.element("message").text(); | ||
| defects.add( | ||
| new DfContext( | ||
| new Defect.Default( | ||
| this.rule, | ||
| Severity.parsed(sever.get()), | ||
| new ObjectName(xmir).get(), | ||
| this.lineno(xml), | ||
| xml.text().get(), | ||
| LtByXsl.experimental(xml) | ||
| message.orElseGet(() -> xml.text().get()), | ||
| LtByXsl.experimental(xml), | ||
| message.map( | ||
| ignored -> | ||
| new Fix( | ||
| new File( | ||
| xmir.xpath("/@source/text()").get(0), | ||
| new Edit(xml.element("edit")) | ||
| ) | ||
| ) | ||
| ) | ||
| .orElseGet(Fix::new) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Marat-Tim maybe we should throw an exception in this case? |
||
| ), | ||
| xml.attribute("context").text().orElse("") | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang.lints; | ||
|
|
||
| import com.github.lombrozo.xnav.Xnav; | ||
| import com.jcabi.xml.XML; | ||
|
|
||
| final class ObjectSource { | ||
| private final Xnav xnav; | ||
|
|
||
| ObjectSource(XML xml) { | ||
| this.xnav = new Xnav(xml.inner()); | ||
| } | ||
|
|
||
| String get() { | ||
| return xnav.attribute("source").text().orElse(""); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Marat-Tim XMIR does not have |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang.lints.fix; | ||
|
|
||
| import com.github.lombrozo.xnav.Xnav; | ||
|
|
||
| public class Create { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Marat-Tim these classes should be package private. We don't want to expose them to the client |
||
| private final String path; | ||
|
|
||
| private final boolean overwrite; | ||
|
|
||
| private final boolean ignoreIfExists; | ||
|
|
||
| public Create(String path, boolean overwrite, boolean ignoreIfExists) { | ||
| this.path = path; | ||
| this.overwrite = overwrite; | ||
| this.ignoreIfExists = ignoreIfExists; | ||
| } | ||
|
|
||
| public Create(Xnav xnav) { | ||
| this( | ||
| xnav.element("path").text().get(), | ||
| Boolean.parseBoolean(xnav.element("overwrite").text().orElse("")), | ||
| Boolean.parseBoolean(xnav.element("ignoreIfExists").text().orElse("")) | ||
| ); | ||
| } | ||
|
|
||
| public String path() { | ||
| return this.path; | ||
| } | ||
|
|
||
| public boolean overwrite() { | ||
| return this.overwrite; | ||
| } | ||
|
|
||
| public boolean ignoreIfExists() { | ||
| return this.ignoreIfExists; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang.lints.fix; | ||
|
|
||
| import com.github.lombrozo.xnav.Xnav; | ||
|
|
||
| public class Delete { | ||
| private final String path; | ||
|
|
||
| private final boolean recursive; | ||
|
|
||
| private final boolean ignoreIfNotExists; | ||
|
|
||
| public Delete(String path, boolean recursive, boolean ignoreIfNotExists) { | ||
| this.path = path; | ||
| this.recursive = recursive; | ||
| this.ignoreIfNotExists = ignoreIfNotExists; | ||
| } | ||
|
|
||
| public Delete(final Xnav xnav) { | ||
| this( | ||
| xnav.element("path").text().get(), | ||
| Boolean.parseBoolean(xnav.element("recursive").text().orElse("")), | ||
| Boolean.parseBoolean(xnav.element("ignoreIfNotExists").text().orElse("")) | ||
| ); | ||
| } | ||
|
|
||
| public String path() { | ||
| return this.path; | ||
| } | ||
|
|
||
| public boolean recursive() { | ||
| return this.recursive; | ||
| } | ||
|
|
||
| public boolean ignoreIfNotExists() { | ||
| return this.ignoreIfNotExists; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang.lints.fix; | ||
|
|
||
| import com.github.lombrozo.xnav.Xnav; | ||
|
|
||
| public class Edit { | ||
| private final Position start; | ||
|
|
||
| private final Position end; | ||
|
|
||
| private final String newText; | ||
|
|
||
| public Edit(final Position start, final Position end, final String newText) { | ||
| this.start = start; | ||
| this.end = end; | ||
| this.newText = newText; | ||
| } | ||
|
|
||
| public Edit(Xnav xnav) { | ||
| this( | ||
| new Position(xnav.element("start")), | ||
| new Position(xnav.element("end")), | ||
| xnav.element("newText").text().get() | ||
| ); | ||
| } | ||
|
|
||
| public Position start() { | ||
| return this.start; | ||
| } | ||
|
|
||
| public Position end() { | ||
| return this.end; | ||
| } | ||
|
|
||
| public String newText() { | ||
| return this.newText; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang.lints.fix; | ||
|
|
||
| import com.github.lombrozo.xnav.Xnav; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| public class File { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Marat-Tim |
||
| private final String path; | ||
| private final Collection<Edit> edits; | ||
|
|
||
| public File(final String path, final Edit... edits) { | ||
| this.path = path; | ||
| this.edits = Arrays.asList(edits); | ||
| } | ||
|
|
||
| public File(final Xnav xnav) { | ||
| this( | ||
| xnav.attribute("path").text().get(), | ||
| xnav.path("edit").map(Edit::new).toArray(Edit[]::new) | ||
| ); | ||
| } | ||
|
|
||
| public String path() { | ||
| return this.path; | ||
| } | ||
|
|
||
| public Collection<Edit> edits() { | ||
| return this.edits; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Marat-Tim to be honest, it is hard to review
Fixarchitecture without unit tests. For now, I don't really understand how it works. So, I suggest to create unit tests, or even test YAML stories (the way we did inLtByXslTest#testsAllLintsByEoandWpaLintsTest#testsAllLintsByEo) to see how it works in practice (EO before fix vs. EO after fix).