refactor: fix clang-tidy auto*, const&, and curly braces (#5083)
This commit is contained in:
@@ -22,7 +22,7 @@ AccountController::AccountController()
|
||||
this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
|
||||
if (args.caller != this)
|
||||
{
|
||||
auto &accs = this->twitch.accounts.raw();
|
||||
const auto &accs = this->twitch.accounts.raw();
|
||||
auto it = std::find(accs.begin(), accs.end(), args.item);
|
||||
assert(it != accs.end());
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ QString sendShoutout(const CommandContext &ctx)
|
||||
{
|
||||
auto *twitchChannel = ctx.twitchChannel;
|
||||
auto channel = ctx.channel;
|
||||
auto words = &ctx.words;
|
||||
const auto *words = &ctx.words;
|
||||
|
||||
if (twitchChannel == nullptr)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,9 @@ FilterSet::FilterSet(const QList<QUuid> &filterIds)
|
||||
for (const auto &f : *filters)
|
||||
{
|
||||
if (filterIds.contains(f->getId()))
|
||||
{
|
||||
this->filters_.insert(f->getId(), f);
|
||||
}
|
||||
}
|
||||
|
||||
this->listener_ =
|
||||
@@ -36,13 +38,17 @@ FilterSet::~FilterSet()
|
||||
bool FilterSet::filter(const MessagePtr &m, ChannelPtr channel) const
|
||||
{
|
||||
if (this->filters_.size() == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
filters::ContextMap context = filters::buildContextMap(m, channel.get());
|
||||
for (const auto &f : this->filters_.values())
|
||||
{
|
||||
if (!f->valid() || !f->filter(context))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -105,7 +105,9 @@ QString Tokenizer::current() const
|
||||
QString Tokenizer::preview() const
|
||||
{
|
||||
if (this->hasNext())
|
||||
{
|
||||
return this->tokens_.at(this->i_);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -172,51 +174,97 @@ const QStringList Tokenizer::allTokens()
|
||||
TokenType Tokenizer::tokenize(const QString &text)
|
||||
{
|
||||
if (text == "&&")
|
||||
{
|
||||
return TokenType::AND;
|
||||
}
|
||||
else if (text == "||")
|
||||
{
|
||||
return TokenType::OR;
|
||||
}
|
||||
else if (text == "(")
|
||||
{
|
||||
return TokenType::LP;
|
||||
}
|
||||
else if (text == ")")
|
||||
{
|
||||
return TokenType::RP;
|
||||
}
|
||||
else if (text == "{")
|
||||
{
|
||||
return TokenType::LIST_START;
|
||||
}
|
||||
else if (text == "}")
|
||||
{
|
||||
return TokenType::LIST_END;
|
||||
}
|
||||
else if (text == ",")
|
||||
{
|
||||
return TokenType::COMMA;
|
||||
}
|
||||
else if (text == "+")
|
||||
{
|
||||
return TokenType::PLUS;
|
||||
}
|
||||
else if (text == "-")
|
||||
{
|
||||
return TokenType::MINUS;
|
||||
}
|
||||
else if (text == "*")
|
||||
{
|
||||
return TokenType::MULTIPLY;
|
||||
}
|
||||
else if (text == "/")
|
||||
{
|
||||
return TokenType::DIVIDE;
|
||||
}
|
||||
else if (text == "==")
|
||||
{
|
||||
return TokenType::EQ;
|
||||
}
|
||||
else if (text == "!=")
|
||||
{
|
||||
return TokenType::NEQ;
|
||||
}
|
||||
else if (text == "%")
|
||||
{
|
||||
return TokenType::MOD;
|
||||
}
|
||||
else if (text == "<")
|
||||
{
|
||||
return TokenType::LT;
|
||||
}
|
||||
else if (text == ">")
|
||||
{
|
||||
return TokenType::GT;
|
||||
}
|
||||
else if (text == "<=")
|
||||
{
|
||||
return TokenType::LTE;
|
||||
}
|
||||
else if (text == ">=")
|
||||
{
|
||||
return TokenType::GTE;
|
||||
}
|
||||
else if (text == "contains")
|
||||
{
|
||||
return TokenType::CONTAINS;
|
||||
}
|
||||
else if (text == "startswith")
|
||||
{
|
||||
return TokenType::STARTS_WITH;
|
||||
}
|
||||
else if (text == "endswith")
|
||||
{
|
||||
return TokenType::ENDS_WITH;
|
||||
}
|
||||
else if (text == "match")
|
||||
{
|
||||
return TokenType::MATCH;
|
||||
}
|
||||
else if (text == "!")
|
||||
{
|
||||
return TokenType::NOT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((text.startsWith("r\"") || text.startsWith("ri\"")) &&
|
||||
@@ -226,14 +274,20 @@ TokenType Tokenizer::tokenize(const QString &text)
|
||||
}
|
||||
|
||||
if (text.front() == '"' && text.back() == '"')
|
||||
{
|
||||
return TokenType::STRING;
|
||||
}
|
||||
|
||||
if (validIdentifiersMap.keys().contains(text))
|
||||
{
|
||||
return TokenType::IDENTIFIER;
|
||||
}
|
||||
|
||||
bool flag;
|
||||
if (text.toInt(&flag); flag)
|
||||
{
|
||||
return TokenType::INT;
|
||||
}
|
||||
}
|
||||
|
||||
return TokenType::NONE;
|
||||
|
||||
@@ -69,27 +69,39 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
|
||||
return 0;
|
||||
case MINUS:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() - right.toInt();
|
||||
}
|
||||
return 0;
|
||||
case MULTIPLY:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() * right.toInt();
|
||||
}
|
||||
return 0;
|
||||
case DIVIDE:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() / right.toInt();
|
||||
}
|
||||
return 0;
|
||||
case MOD:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() % right.toInt();
|
||||
}
|
||||
return 0;
|
||||
case OR:
|
||||
if (convertVariantTypes(left, right, QMetaType::Bool))
|
||||
{
|
||||
return left.toBool() || right.toBool();
|
||||
}
|
||||
return false;
|
||||
case AND:
|
||||
if (convertVariantTypes(left, right, QMetaType::Bool))
|
||||
{
|
||||
return left.toBool() && right.toBool();
|
||||
}
|
||||
return false;
|
||||
case EQ:
|
||||
if (variantTypesMatch(left, right, QMetaType::QString))
|
||||
@@ -107,19 +119,27 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
|
||||
return !looselyCompareVariants(left, right);
|
||||
case LT:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() < right.toInt();
|
||||
}
|
||||
return false;
|
||||
case GT:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() > right.toInt();
|
||||
}
|
||||
return false;
|
||||
case LTE:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() <= right.toInt();
|
||||
}
|
||||
return false;
|
||||
case GTE:
|
||||
if (convertVariantTypes(left, right, QMetaType::Int))
|
||||
{
|
||||
return left.toInt() >= right.toInt();
|
||||
}
|
||||
return false;
|
||||
case CONTAINS:
|
||||
if (variantIs(left, QMetaType::QStringList) &&
|
||||
@@ -215,22 +235,30 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
|
||||
|
||||
// list must be two items
|
||||
if (list.size() != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// list must be a regular expression and an int
|
||||
if (variantIsNot(list.at(0),
|
||||
QMetaType::QRegularExpression) ||
|
||||
variantIsNot(list.at(1), QMetaType::Int))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto match =
|
||||
list.at(0).toRegularExpression().match(matching);
|
||||
|
||||
// if matched, return nth capture group. Otherwise, return ""
|
||||
if (match.hasMatch())
|
||||
{
|
||||
return match.captured(list.at(1).toInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
@@ -263,9 +291,13 @@ PossibleType BinaryOperation::synthesizeType(const TypingContext &context) const
|
||||
{
|
||||
case PLUS:
|
||||
if (left == Type::String)
|
||||
{
|
||||
return TypeClass{Type::String}; // String concatenation
|
||||
}
|
||||
else if (left == Type::Int && right == Type::Int)
|
||||
{
|
||||
return TypeClass{Type::Int};
|
||||
}
|
||||
|
||||
return IllTyped{this, "Can only add Ints or concatenate a String"};
|
||||
case MINUS:
|
||||
@@ -273,13 +305,17 @@ PossibleType BinaryOperation::synthesizeType(const TypingContext &context) const
|
||||
case DIVIDE:
|
||||
case MOD:
|
||||
if (left == Type::Int && right == Type::Int)
|
||||
{
|
||||
return TypeClass{Type::Int};
|
||||
}
|
||||
|
||||
return IllTyped{this, "Can only perform operation with Ints"};
|
||||
case OR:
|
||||
case AND:
|
||||
if (left == Type::Bool && right == Type::Bool)
|
||||
{
|
||||
return TypeClass{Type::Bool};
|
||||
}
|
||||
|
||||
return IllTyped{this,
|
||||
"Can only perform logical operations with Bools"};
|
||||
@@ -292,37 +328,53 @@ PossibleType BinaryOperation::synthesizeType(const TypingContext &context) const
|
||||
case LTE:
|
||||
case GTE:
|
||||
if (left == Type::Int && right == Type::Int)
|
||||
{
|
||||
return TypeClass{Type::Bool};
|
||||
}
|
||||
|
||||
return IllTyped{this, "Can only perform comparisons with Ints"};
|
||||
case STARTS_WITH:
|
||||
case ENDS_WITH:
|
||||
if (isList(left))
|
||||
{
|
||||
return TypeClass{Type::Bool};
|
||||
}
|
||||
if (left == Type::String && right == Type::String)
|
||||
{
|
||||
return TypeClass{Type::Bool};
|
||||
}
|
||||
|
||||
return IllTyped{
|
||||
this,
|
||||
"Can only perform starts/ends with a List or two Strings"};
|
||||
case CONTAINS:
|
||||
if (isList(left) || left == Type::Map)
|
||||
{
|
||||
return TypeClass{Type::Bool};
|
||||
}
|
||||
if (left == Type::String && right == Type::String)
|
||||
{
|
||||
return TypeClass{Type::Bool};
|
||||
}
|
||||
|
||||
return IllTyped{
|
||||
this,
|
||||
"Can only perform contains with a List, a Map, or two Strings"};
|
||||
case MATCH: {
|
||||
if (left != Type::String)
|
||||
{
|
||||
return IllTyped{this,
|
||||
"Left argument of match must be a String"};
|
||||
}
|
||||
|
||||
if (right == Type::RegularExpression)
|
||||
{
|
||||
return TypeClass{Type::Bool};
|
||||
if (right == Type::MatchingSpecifier) // group capturing
|
||||
}
|
||||
if (right == Type::MatchingSpecifier)
|
||||
{ // group capturing
|
||||
return TypeClass{Type::String};
|
||||
}
|
||||
|
||||
return IllTyped{this, "Can only match on a RegularExpression or a "
|
||||
"MatchingSpecifier"};
|
||||
|
||||
@@ -123,7 +123,9 @@ struct Deserialize<chatterino::HighlightBadge> {
|
||||
|
||||
auto _color = QColor(encodedColor);
|
||||
if (!_color.isValid())
|
||||
{
|
||||
_color = chatterino::HighlightBadge::FALLBACK_HIGHLIGHT_COLOR;
|
||||
}
|
||||
|
||||
return chatterino::HighlightBadge(_name, _displayName, _showInMentions,
|
||||
_hasAlert, _hasSound, _soundUrl,
|
||||
|
||||
@@ -164,7 +164,9 @@ struct Deserialize<chatterino::HighlightPhrase> {
|
||||
|
||||
auto _color = QColor(encodedColor);
|
||||
if (!_color.isValid())
|
||||
{
|
||||
_color = chatterino::HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR;
|
||||
}
|
||||
|
||||
return chatterino::HighlightPhrase(_pattern, _showInMentions, _hasAlert,
|
||||
_hasSound, _isRegex,
|
||||
|
||||
@@ -66,7 +66,7 @@ std::vector<QShortcut *> HotkeyController::shortcutsForCategory(
|
||||
continue;
|
||||
}
|
||||
auto createShortcutFromKeySeq = [&](QKeySequence qs) {
|
||||
auto s = new QShortcut(qs, parent);
|
||||
auto *s = new QShortcut(qs, parent);
|
||||
s->setContext(hotkey->getContext());
|
||||
auto functionPointer = target->second;
|
||||
QObject::connect(s, &QShortcut::activated, parent,
|
||||
@@ -101,7 +101,7 @@ void HotkeyController::save()
|
||||
|
||||
std::shared_ptr<Hotkey> HotkeyController::getHotkeyByName(QString name)
|
||||
{
|
||||
for (auto &hotkey : this->hotkeys_)
|
||||
for (const auto &hotkey : this->hotkeys_)
|
||||
{
|
||||
if (hotkey->name() == name)
|
||||
{
|
||||
@@ -115,7 +115,7 @@ int HotkeyController::replaceHotkey(QString oldName,
|
||||
std::shared_ptr<Hotkey> newHotkey)
|
||||
{
|
||||
int i = 0;
|
||||
for (auto &hotkey : this->hotkeys_)
|
||||
for (const auto &hotkey : this->hotkeys_)
|
||||
{
|
||||
if (hotkey->name() == oldName)
|
||||
{
|
||||
@@ -544,7 +544,7 @@ void HotkeyController::tryAddDefault(std::set<QString> &addedHotkeys,
|
||||
void HotkeyController::showHotkeyError(const std::shared_ptr<Hotkey> &hotkey,
|
||||
QString warning)
|
||||
{
|
||||
auto msgBox = new QMessageBox(
|
||||
auto *msgBox = new QMessageBox(
|
||||
QMessageBox::Icon::Warning, "Hotkey error",
|
||||
QString(
|
||||
"There was an error while executing your hotkey named \"%1\": \n%2")
|
||||
|
||||
@@ -143,11 +143,15 @@ const std::optional<ImagePtr> &ModerationAction::getImage() const
|
||||
if (this->imageToLoad_ != 0)
|
||||
{
|
||||
if (this->imageToLoad_ == 1)
|
||||
{
|
||||
this->image_ =
|
||||
Image::fromResourcePixmap(getResources().buttons.ban);
|
||||
}
|
||||
else if (this->imageToLoad_ == 2)
|
||||
{
|
||||
this->image_ =
|
||||
Image::fromResourcePixmap(getResources().buttons.trashCan);
|
||||
}
|
||||
}
|
||||
|
||||
return this->image_;
|
||||
|
||||
@@ -225,7 +225,7 @@ void NotificationController::removeFakeChannel(const QString channelName)
|
||||
|
||||
for (int i = snapshotLength - 1; i >= end; --i)
|
||||
{
|
||||
auto &s = snapshot[i];
|
||||
const auto &s = snapshot[i];
|
||||
|
||||
if (s->messageText == liveMessageSearchText)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user