-
Notifications
You must be signed in to change notification settings - Fork 17
feat(#123): Program also use Source for linting #575
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
Draft
Marat-Tim
wants to merge
3
commits into
objectionary:master
Choose a base branch
from
Marat-Tim:123
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+245
−146
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang.lints; | ||
|
|
||
| import com.jcabi.xml.XML; | ||
| import com.jcabi.xml.XMLDocument; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
| import org.cactoos.iterable.Sticky; | ||
| import org.cactoos.list.ListOf; | ||
| import org.cactoos.list.Synced; | ||
|
|
||
| /** | ||
| * Whole EO package, as collection of XMIR sources to analyze. | ||
| * @since 0.1.0 | ||
|
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 let's place correct version of the future release |
||
| */ | ||
| final class EoPackage { | ||
|
|
||
| /** | ||
| * Collection of wpa lints, preloaded on JVM start. | ||
| */ | ||
| private static final Iterable<Lint<Map<String, XML>>> WPA = new Synced<>( | ||
| new ListOf<>( | ||
| new Sticky<>( | ||
| new PkWpa() | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| /** | ||
| * Lints to use. | ||
| */ | ||
| private final Iterable<Lint<Map<String, XML>>> lints; | ||
|
|
||
| /** | ||
| * The package of XMIR files. | ||
| */ | ||
| private final Map<String, XML> pkg; | ||
|
|
||
| /** | ||
| * Ctor. | ||
| * @param dirs The directory | ||
| * @throws IOException If fails | ||
| */ | ||
| EoPackage(final Path... dirs) throws IOException { | ||
| this(Arrays.asList(dirs)); | ||
| } | ||
|
|
||
| /** | ||
| * Ctor. | ||
| * | ||
| * <p>Pay attention, it's important to use {@link Collection} as a type | ||
| * of argument, because {@link Path} implements {@link Iterable}.</p> | ||
| * | ||
| * @param dirs The directory | ||
| * @throws IOException If fails | ||
| */ | ||
| EoPackage(final Collection<Path> dirs) throws IOException { | ||
| this(EoPackage.discover(dirs)); | ||
| } | ||
|
|
||
| /** | ||
| * Ctor. | ||
| * @param map The map with them | ||
| */ | ||
| EoPackage(final Map<String, XML> map) { | ||
| this(map, EoPackage.WPA); | ||
| } | ||
|
|
||
| /** | ||
| * Ctor. | ||
| * @param map The map with them | ||
| * @param list The lints | ||
| */ | ||
| EoPackage(final Map<String, XML> map, final Iterable<Lint<Map<String, XML>>> list) { | ||
| this.pkg = Collections.unmodifiableMap(map); | ||
| this.lints = list; | ||
| } | ||
|
|
||
| /** | ||
| * Package with disabled lints. | ||
| * @param names Lint names | ||
| * @return Package analysis without specifics names | ||
| */ | ||
| public EoPackage without(final String... names) { | ||
| return new EoPackage(this.pkg, new WpaWithout(names)); | ||
| } | ||
|
|
||
| /** | ||
| * Find all possible defects in the EO package. | ||
| * @return All defects found | ||
| */ | ||
| public Collection<Defect> defects() { | ||
| final Collection<Defect> messages = new ArrayList<>(0); | ||
| for (final Lint<Map<String, XML>> lint : this.lints) { | ||
| try { | ||
| messages.addAll(new ScopedDefects(lint.defects(this.pkg), "WPA")); | ||
| } catch (final IOException exception) { | ||
| throw new IllegalStateException( | ||
| String.format( | ||
| "Failed to find defects in the '%s' package with '%s' lint", | ||
| this.pkg, | ||
| lint | ||
| ), | ||
| exception | ||
| ); | ||
| } | ||
| } | ||
| return messages; | ||
| } | ||
|
|
||
| /** | ||
| * Discover all XMIR files in the directory. | ||
| * @param dirs The directories to search for XMIR files in (recursively) | ||
| * @return Map of XMIR files | ||
| * @throws IOException If fails | ||
| */ | ||
| private static Map<String, XML> discover(final Iterable<Path> dirs) throws IOException { | ||
| final Map<String, XML> map = new HashMap<>(0); | ||
| for (final Path dir : dirs) { | ||
| map.putAll(EoPackage.discover(dir)); | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| /** | ||
| * Discover all XMIR files in the directory. | ||
| * @param dir The directories to search for XMIR files in (recursively) | ||
| * @return Map of XMIR files | ||
| * @throws IOException If fails | ||
| */ | ||
| private static Map<String, XML> discover(final Path dir) throws IOException { | ||
| try (Stream<Path> walk = Files.walk(dir)) { | ||
| return walk | ||
| .filter(Files::isRegularFile) | ||
| .collect( | ||
| Collectors.toMap( | ||
| path -> new XmirKey(path, dir).asString(), | ||
| path -> { | ||
| try { | ||
| return new XMLDocument(path); | ||
| } catch (final FileNotFoundException ex) { | ||
| throw new IllegalArgumentException(ex); | ||
| } | ||
| } | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,8 @@ | |
| import org.cactoos.list.ListOf; | ||
|
|
||
| /** | ||
| * A collection of lints for Whole Program Analysis (WPA), | ||
| * provided by the {@link Program} class. | ||
| * A collection of lints for Whole Package Analysis (WPA), | ||
|
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 here, we should stay with |
||
| * provided by the {@link EoPackage} class. | ||
| * | ||
| * <p>This class is thread-safe.</p> | ||
| * | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 let's use
new MapOf<>()from org.cactoos for better consistency in the codebase