objectionary / objectionary/lints

Source.fix() applies lint fixes unconditionally, mutating clean XMIR

Open
#1,373 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
14
Forks
39
Avg merge
22h 54m
Merged PRs (30d)
90

Description

Problem

Source.fix() applies every lint's fix unconditionally, even when the input XMIR has no defects for that lint. A fix that removes/moves nodes in expectation of a defect will mutate a perfectly clean document.

Root cause

src/main/java/org/eolang/lints/Source.java:89-95:

private XML fix(final XML xmir) {
    XML result = xmir;
    for (final Lint lint : Source.MONO.value()) {
        result = lint.fix().apply(result);
    }
    return result;
}

There is no gate on lint.defects(result). For example, the unsorted-metas fix (an identity template that also sorts metas) will reorder metas even in a document whose metas are already sorted, and will touch documents that carry no metas at all.

Minimal example

final XML before = new XMLDocument("<object><metas><meta><head>spdx</head><tail>MIT</tail></meta></metas><o name=\"x\"/></object>");
final XML after = new Source(before).fix(); // metas re-serialized/reordered even though no defect exists

Expected behavior

A lint's fix should be applied only when that lint reported at least one defect on the current document (or the unconditional behavior should be documented explicitly in the javadoc of Lint.fix()/Source.fix()).

Related

  • src/main/java/org/eolang/lints/Fix.java — the Fix contract; a fix may legitimately assume a defect was present.
  • Existing fix pack: fixes/unsorted-metas/sorts-version-and-spdx.yaml.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/java/org/eolang/lints/Source.java:89-95 and read the Fix contract in src/main/java/org/eolang/lints/Fix.java, then inspect the unsorted-metas fix pack. Run the relevant test suite and verify that clean XMIR remains unchanged while fixes still apply when defects are present.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.