diff --git a/CHANGES.md b/CHANGES.md index 051a159e..59a79bf6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLint.java b/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLint.java index c4c6609b..d71ea6b6 100644 --- a/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLint.java +++ b/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLint.java @@ -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); } /** @@ -225,7 +218,6 @@ public void run(final Collection paths) throws IOException, ReflectiveOper final List ignoreMatchers = checksConfig.getIgnores().stream() .map(fs::getPathMatcher) .collect(Collectors.toList()); - final Integer untabify = this.config.getUntabify(); final long maxInfractions = this.config.getMaxInfractions(); // Sorting. @@ -241,7 +233,7 @@ public void run(final Collection 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 diff --git a/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLintConfiguration.java b/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLintConfiguration.java index de387819..897e3bec 100644 --- a/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLintConfiguration.java +++ b/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/MagikLintConfiguration.java @@ -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"; @@ -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. diff --git a/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/Main.java b/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/Main.java index 53c47a0b..90d74fe9 100644 --- a/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/Main.java +++ b/magik-lint/src/main/java/nl/ramsolutions/sw/magik/lint/Main.java @@ -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") @@ -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); @@ -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); diff --git a/magik-squid/src/main/java/nl/ramsolutions/sw/Utils.java b/magik-squid/src/main/java/nl/ramsolutions/sw/Utils.java deleted file mode 100644 index 5a898908..00000000 --- a/magik-squid/src/main/java/nl/ramsolutions/sw/Utils.java +++ /dev/null @@ -1,44 +0,0 @@ -package nl.ramsolutions.sw; - -import java.util.stream.Collectors; - -/** - * Utility functions. - */ -public final class Utils { - - private Utils() { - } - - /** - * Untabify a string. - * @param text Text to untabify. - * @param tabSize Tab size. - * @return Untabified text. - */ - public static String untabify(final String text, final int tabSize) { - // From: https://stackoverflow.com/questions/11722855/expand-the-tabs-in-java/40834203#40834203 - final int[] col = new int[1]; - return text.chars() - .mapToObj(c -> { - switch (c) { - case '\t': - int expandBy = tabSize - col[0] % tabSize; - col[0] += expandBy; - return " ".repeat(expandBy); - - case '\n': - col[0] = 0; - break; - - default: - col[0]++; - break; - } - - return String.valueOf((char) c); - }) - .collect(Collectors.joining()); - } - -} diff --git a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/MagikFile.java b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/MagikFile.java index 31a16dda..e9b3d316 100644 --- a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/MagikFile.java +++ b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/MagikFile.java @@ -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 definitions; @@ -40,17 +39,6 @@ public class MagikFile { private final Map>> 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. @@ -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; } /** @@ -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; } /** @@ -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. @@ -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}.