Skip to content

fix: Suppress Sorbet errors by default. #136

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

Merged
merged 1 commit into from
Oct 5, 2022
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
6 changes: 4 additions & 2 deletions core/Error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ string ErrorSection::toString(const GlobalState &gs) const {
string Error::toString(const GlobalState &gs) const {
stringstream buf;
buf << RESET_STYLE << FILE_POS_STYLE << loc.filePosToString(gs) << RESET_STYLE << ": " << ERROR_COLOR
<< restoreColors(header, ERROR_COLOR) << RESET_COLOR << LOW_NOISE_COLOR << " " << gs.errorUrlBase << what.code
<< RESET_COLOR;
<< restoreColors(header, ERROR_COLOR) << RESET_COLOR;
if (what.code != 25900) { // SCIPRubyDebug
buf << LOW_NOISE_COLOR << " " << gs.errorUrlBase << what.code << RESET_COLOR;
}
if (loc.exists()) {
auto fileLength = loc.file().data(gs).source().size();
if (loc.beginPos() > fileLength || loc.endPos() > fileLength) {
Expand Down
9 changes: 8 additions & 1 deletion core/GlobalState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,7 @@ unique_ptr<GlobalState> GlobalState::deepCopy(bool keepId) const {
auto result = make_unique<GlobalState>(this->errorQueue, this->epochManager);

result->silenceErrors = this->silenceErrors;
result->unsilenceErrors = this->unsilenceErrors;
result->autocorrect = this->autocorrect;
result->ensureCleanStrings = this->ensureCleanStrings;
result->runningUnderAutogen = this->runningUnderAutogen;
Expand Down Expand Up @@ -2055,6 +2056,7 @@ unique_ptr<GlobalState> GlobalState::copyForIndex() const {
result->files = this->files;
result->fileRefByPath = this->fileRefByPath;
result->silenceErrors = this->silenceErrors;
result->unsilenceErrors = this->unsilenceErrors;
result->autocorrect = this->autocorrect;
result->ensureCleanStrings = this->ensureCleanStrings;
result->runningUnderAutogen = this->runningUnderAutogen;
Expand Down Expand Up @@ -2141,9 +2143,14 @@ bool GlobalState::shouldReportErrorOn(Loc loc, ErrorClass what) const {
if (what.minLevel == StrictLevel::Internal) {
return true;
}
if (this->silenceErrors) {
if (this->silenceErrors && !this->unsilenceErrors) {
return false;
}
if (this->isSCIPRuby && !this->unsilenceErrors) {
if (what.code != 25900) { // SCIPRubyDebug
return false;
}
}
if (suppressedErrorClasses.count(what.code) != 0) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions core/GlobalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class GlobalState final {

int globalStateId;
bool silenceErrors = false;
bool unsilenceErrors = false;
bool autocorrect = false;

// We have a lot of internal names of form `<something>` that's chosen with `<` and `>` as you can't make
Expand Down
8 changes: 7 additions & 1 deletion main/options/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ buildOptions(const vector<pipeline::semantic_extension::SemanticExtensionProvide
cxxopts::value<string>()->default_value(empty.inlineInput), "string");
options.add_options()("files", "Input files", cxxopts::value<vector<string>>());
options.add_options()("q,quiet", "Silence all non-critical errors");
options.add_options()("unquiet", "(scip-ruby) Show non-critical errors, which are hidden by default");
options.add_options()("v,verbose", "Verbosity level [0-3]");
options.add_options()("h", "Show short help");
options.add_options()("help", "Show long help");
Expand Down Expand Up @@ -808,9 +809,14 @@ void readOptions(Options &opts,
opts.stopAfterPhase = extractStopAfter(raw, logger);

opts.silenceErrors = raw["quiet"].as<bool>();
opts.unsilenceErrors = raw["unquiet"].as<bool>();
if (opts.silenceErrors && opts.unsilenceErrors) {
logger->error("You can't pass both `{}` and `{}`", "--unquiet", "--quiet");
throw EarlyReturnWithCode(1);
}
opts.autocorrect = raw["autocorrect"].as<bool>();
opts.inlineInput = raw["e"].as<string>();
if (opts.autocorrect && opts.silenceErrors) {
if (opts.autocorrect && opts.silenceErrors && !opts.unsilenceErrors) {
logger->error("You may not use autocorrect when silencing errors.");
throw EarlyReturnWithCode(1);
}
Expand Down
1 change: 1 addition & 0 deletions main/options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct Options {
bool suggestTyped = false;
std::optional<std::string> suggestUnsafe = std::nullopt;
bool silenceErrors = false;
bool unsilenceErrors = false;
bool silenceDevMessage = false;
bool suggestSig = false;
bool suppressNonCriticalErrors = false;
Expand Down
1 change: 1 addition & 0 deletions main/options/test/options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ TEST_CASE("DefaultConstructorMatchesReadOptions") {
CHECK_EQ(empty.showProgress, opts.showProgress);
CHECK_EQ(empty.suggestTyped, opts.suggestTyped);
CHECK_EQ(empty.silenceErrors, opts.silenceErrors);
CHECK_EQ(empty.unsilenceErrors, opts.unsilenceErrors);
CHECK_EQ(empty.silenceDevMessage, opts.silenceDevMessage);
CHECK_EQ(empty.suggestSig, opts.suggestSig);
CHECK_EQ(empty.suppressNonCriticalErrors, opts.suppressNonCriticalErrors);
Expand Down
1 change: 1 addition & 0 deletions main/realmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ int realmain(int argc, char *argv[]) {
if (opts.silenceErrors) {
gs->silenceErrors = true;
}
gs->unsilenceErrors = opts.unsilenceErrors;
if (opts.autocorrect) {
gs->autocorrect = true;
}
Expand Down
2 changes: 1 addition & 1 deletion scip_indexer/Debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace sorbet::scip_indexer {

constexpr sorbet::core::ErrorClass SCIPRubyDebug{400, sorbet::core::StrictLevel::False};
constexpr sorbet::core::ErrorClass SCIPRubyDebug{25900, sorbet::core::StrictLevel::False};

void _log_debug(const sorbet::core::GlobalState &gs, sorbet::core::Loc loc, std::string s) {
if (auto e = gs.beginError(loc, SCIPRubyDebug)) {
Expand Down