Skip to content

Commit

Permalink
Drop --untabify option from magik-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Sep 22, 2023
1 parent 511399b commit e67ea9e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 122 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
- Implementation provider now provides impementations of abstract methods.
- Add SelectionRangeProvider to magik-language-server.
- Drop templated check support, including checks CommentRegularExpressionCheck and XPathCheck.
- Fix CommentedCodeCheck matching too many things as Magik code
- Fix CommentedCodeCheck matching too many things as Magik code.
- Drop `--untabify` option from magik-lint.
- Various small fixes.

0.7.1 (2023-02-21)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,23 @@ public MagikLint(final MagikLintConfiguration configuration, final Reporter repo
}

/**
* Build context for a file, untabifying if needed.
*
* @param path Path to file
* @param untabify Untabify to N-spaces, if given
* Build context for a file.
* @param path Path to file
* @return Visitor context for file.
*/
private MagikFile buildMagikFile(final Path path, final @Nullable Integer untabify) {
private MagikFile buildMagikFile(final Path path) {
final Charset charset = FileCharsetDeterminer.determineCharset(path);

byte[] encoded = null;
try {
encoded = Files.readAllBytes(path);
} catch (IOException exception) {
} catch (final IOException exception) {
LOGGER.error(exception.getMessage(), exception);
}

final URI uri = path.toUri();

final String originalFileContents = new String(encoded, charset);
final String fileContents = untabify != null
? Utils.untabify(originalFileContents, untabify)
: originalFileContents;

return new MagikFile(uri, fileContents, originalFileContents);
final String fileContents = new String(encoded, charset);
return new MagikFile(uri, fileContents);
}

/**
Expand Down Expand Up @@ -225,7 +218,6 @@ public void run(final Collection<Path> paths) throws IOException, ReflectiveOper
final List<PathMatcher> ignoreMatchers = checksConfig.getIgnores().stream()
.map(fs::getPathMatcher)
.collect(Collectors.toList());
final Integer untabify = this.config.getUntabify();
final long maxInfractions = this.config.getMaxInfractions();

// Sorting.
Expand All @@ -241,7 +233,7 @@ public void run(final Collection<Path> paths) throws IOException, ReflectiveOper
}
return !matches;
})
.map(path -> this.buildMagikFile(path, untabify))
.map(path -> this.buildMagikFile(path))
.map(magikFile -> this.runChecksOnFile(magikFile, holders))
.flatMap(List::stream)
// ensure ordering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
public class MagikLintConfiguration {

private static final String KEY_UNTABIFY = "untabify";
private static final String KEY_MAX_INFRACTIONS = "max-infractions";
private static final String KEY_COLUMN_OFFSET = "column-offset";
private static final String KEY_MSG_TEMPLATE = "msg-template";
Expand Down Expand Up @@ -42,24 +41,6 @@ public Path getPath() {
return this.path;
}

/**
* Get untabify.
* @return Untabify.
*/
@CheckForNull
public Integer getUntabify() {
final String untabifyStr = this.properties.getPropertyString(KEY_UNTABIFY);
if (untabifyStr == null) {
return null;
}

return Integer.parseInt(untabifyStr);
}

public void setUntabify(final Integer untabify) {
this.properties.setProperty(KEY_UNTABIFY, untabify);
}

/**
* Get max infractions.
* @return Max infractions.
Expand Down
13 changes: 0 additions & 13 deletions magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ public final class Main {
.hasArg()
.type(PatternOptionBuilder.NUMBER_VALUE)
.build();
private static final Option OPTION_UNTABIFY = Option.builder()
.longOpt("untabify")
.desc("Expand tabs to N spaces")
.hasArg()
.type(PatternOptionBuilder.NUMBER_VALUE)
.build();
private static final Option OPTION_DEBUG = Option.builder()
.longOpt("debug")
.desc("Enable showing of debug information")
Expand All @@ -84,7 +78,6 @@ public final class Main {
OPTIONS.addOption(OPTION_MSG_TEMPLATE);
OPTIONS.addOption(OPTION_RCFILE);
OPTIONS.addOption(OPTION_SHOW_CHECKS);
OPTIONS.addOption(OPTION_UNTABIFY);
OPTIONS.addOption(OPTION_COLUMN_OFFSET);
OPTIONS.addOption(OPTION_MAX_INFRACTIONS);
OPTIONS.addOption(OPTION_DEBUG);
Expand Down Expand Up @@ -234,12 +227,6 @@ public static void main(final String[] args) throws ParseException, IOException,
}

private static void copyOptionsToConfig(final CommandLine commandLine, final MagikLintConfiguration config) {
if (commandLine.hasOption(OPTION_UNTABIFY)) {
final String value = commandLine.getOptionValue(OPTION_UNTABIFY);
final Integer untabify = Integer.parseInt(value);
config.setUntabify(untabify);
}

if (commandLine.hasOption(OPTION_MAX_INFRACTIONS)) {
final String value = commandLine.getOptionValue(OPTION_MAX_INFRACTIONS);
final Long maxInfractions = Long.parseLong(value);
Expand Down
44 changes: 0 additions & 44 deletions magik-squid/src/main/java/nl/ramsolutions/sw/Utils.java

This file was deleted.

30 changes: 0 additions & 30 deletions magik-squid/src/main/java/nl/ramsolutions/sw/magik/MagikFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class MagikFile {

private final URI uri;
private final String source;
private final String originalSource;
private AstNode astNode;
private GlobalScope globalScope;
private List<Definition> definitions;
Expand All @@ -40,17 +39,6 @@ public class MagikFile {
private final Map<CommentInstructionReader.InstructionType, Map<Scope, Map<String, String>>> scopeInstructions
= new HashMap<>();

/**
* Constructor.
* @param uri URI.
* @param source Source.
*/
public MagikFile(final URI uri, final String source, final String originalSource) {
this.uri = uri;
this.source = source;
this.originalSource = originalSource;
}

/**
* Constructor.
* @param uri URI.
Expand All @@ -59,7 +47,6 @@ public MagikFile(final URI uri, final String source, final String originalSource
public MagikFile(final URI uri, final String source) {
this.uri = uri;
this.source = source;
this.originalSource = source;
}

/**
Expand All @@ -80,7 +67,6 @@ public MagikFile(final Path path) throws IOException {
this.uri = path.toUri();
final Charset charset = FileCharsetDeterminer.determineCharset(path);
this.source = Files.readString(path, charset);
this.originalSource = this.source;
}

/**
Expand All @@ -99,14 +85,6 @@ public String getSource() {
return this.source;
}

/**
* Get the original (untabified) source text.
* @return Original source text.
*/
public String getOriginalSource() {
return this.originalSource;
}

/**
* Get the source lines.
* @return Source lines.
Expand All @@ -115,14 +93,6 @@ public String[] getSourceLines() {
return this.source.split("\r\n|\n|\r");
}

/**
* Get the original source lines.
* @return Original source lines.
*/
public String[] getOriginalSourceLines() {
return this.originalSource.split("\r\n|\n|\r");
}

/**
* Parse the text for this file and return the top level {@link AstNode}.
* @return Top level {@link AstNode}.
Expand Down

0 comments on commit e67ea9e

Please sign in to comment.