Skip to content
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

chore: update @Nullable and putout version #22

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/codemods/ApplyCodemod.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Option;
import org.openrewrite.internal.lang.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/openrewrite/codemods/ESLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Option;
import org.openrewrite.SourceFile;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.marker.Marker;
import org.openrewrite.marker.Markers;
import org.openrewrite.marker.SearchResult;
Expand Down Expand Up @@ -60,24 +60,24 @@ public class ESLint extends NodeBasedRecipe {

@Option(displayName = "Parser to be used by ESLint",
description = "Parser used by ESLint to parse the source files. Defaults to `@typescript-eslint/parser`. " +
"See [ESLint documentation](https://eslint.org/docs/latest/use/configure/parsers) for more details.",
"See [ESLint documentation](https://eslint.org/docs/latest/use/configure/parsers) for more details.",
example = "esprima",
required = false)
@Nullable
String parser;

@Option(displayName = "List of parser options for ESLint",
description = "A list of parser options for ESLint. The format is `key: value`. Defaults to " +
"`ecmaVersion: \"latest\", ecmaFeatures: { jsx: true }, sourceType: \"module\"`. See " +
"[ESLint documentation](https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options) for more details.",
"`ecmaVersion: \"latest\", ecmaFeatures: { jsx: true }, sourceType: \"module\"`. See " +
"[ESLint documentation](https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options) for more details.",
example = "ecmaVersion: 6, ecmaFeatures: { jsx: true }",
required = false)
@Nullable
List<String> parserOptions;

@Option(displayName = "Allow inline configuration for ESLint",
description = "Whether inline config comments are allowed. Defaults to `false`. See " +
"[ESLint documentation](https://eslint.org/docs/latest/use/configure/rules#disabling-inline-comments) for more details.",
"[ESLint documentation](https://eslint.org/docs/latest/use/configure/rules#disabling-inline-comments) for more details.",
example = "true",
required = false)
@Nullable
Expand Down Expand Up @@ -113,10 +113,10 @@ public class ESLint extends NodeBasedRecipe {

@Option(displayName = "ESLint rules and rule configuration",
description = "List of rules to be checked by ESLint. Optionally, the severity and other rule options can " +
"also be specified as e.g. `off`, `warn` or `[\"error\", \"always\"]`. " +
"The severity `off` is useful when the rule is declared by an extended " +
"[shareable config](https://eslint.org/docs/latest/extend/ways-to-extend#shareable-configs). " +
"For more information, see the [ESLint documentation](https://eslint.org/docs/latest/use/configure/rules)",
"also be specified as e.g. `off`, `warn` or `[\"error\", \"always\"]`. " +
"The severity `off` is useful when the rule is declared by an extended " +
"[shareable config](https://eslint.org/docs/latest/extend/ways-to-extend#shareable-configs). " +
"For more information, see the [ESLint documentation](https://eslint.org/docs/latest/use/configure/rules)",
example = "eqeqeq: warn, multiline-comment-style: [\"error\", \"starred-block\"], prettier/prettier",
required = false)
@Nullable
Expand All @@ -131,8 +131,8 @@ public class ESLint extends NodeBasedRecipe {

@Option(displayName = "Override config file",
description = "Allows specifying the full ESLint configuration file contents as multiline JSON. " +
"See [ESLint documentation](https://eslint.org/docs/latest/use/configure/configuration-files) for more details.\n\n" +
"Note that this will override any other configuration options.",
"See [ESLint documentation](https://eslint.org/docs/latest/use/configure/configuration-files) for more details.\n\n" +
"Note that this will override any other configuration options.",
required = false)
@Nullable
String configFile;
Expand All @@ -145,7 +145,7 @@ public String getDisplayName() {
@Override
public String getDescription() {
return "Run [ESLint](https://eslint.org/) across the code to fix common static analysis issues in the code.\n\n" +
"This requires the code to have an existing ESLint configuration.";
"This requires the code to have an existing ESLint configuration.";
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/openrewrite/codemods/NodeBasedRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.quark.Quark;
import org.openrewrite.scheduling.WorkingDirectoryExecutionContextView;
import org.openrewrite.text.PlainText;
Expand Down Expand Up @@ -167,7 +168,7 @@ protected void processOutput(Path out, Accumulator acc, ExecutionContext ctx) {
public TreeVisitor<?, ExecutionContext> getVisitor(Accumulator acc) {
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
public @Nullable Tree visit(@Nullable Tree tree, @NotNull ExecutionContext ctx) {
if (tree instanceof SourceFile) {
SourceFile sourceFile = (SourceFile) tree;
// TODO parse sources like JSON where parser doesn't require an environment
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/openrewrite/codemods/Putout.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Option;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.scheduling.WorkingDirectoryExecutionContextView;

import java.io.IOException;
Expand All @@ -45,8 +45,8 @@ public String getDescription() {
return "Run [Putout](https://github.com/coderaiser/putout) on your projects.";
}

@Option(displayName = "Config file",
description = "A list of rules to enable",
@Option(displayName = "Rules",
description = "Names of rules to enable. If not provided, all rules are enabled.",
required = false)
@Nullable
Set<String> rules;
Expand All @@ -55,15 +55,16 @@ public String getDescription() {
protected List<String> getNpmCommand(Accumulator acc, ExecutionContext ctx) {
List<String> commands = new ArrayList<>();
String executable = "${nodeModules}/.bin/putout";

if (rules != null) {
commands.add(executable + " ${repoDir} --disable-all || true"); // hacky because disable-all throws

// enable only rules that are provided
for (String rule : rules) {
commands.add(executable + " ${repoDir} --enable " + rule);
}
}


commands.add(executable + " ${repoDir}" + " --fix");
return commands;
}
Expand All @@ -87,6 +88,7 @@ protected void runNode(Accumulator acc, ExecutionContext ctx) {
.replace("${nodeModules}", nodeModules.toString())
.replace("${repoDir}", ".")
.replace("${parser}", acc.parser()));

}

Path out = null, err = null;
Expand Down
Loading