srctree

Robin Linden parent 8b9a3985 4b57d29e
meta/clang-tidy: Enable readability-else-after-return

inlinesplit
.clang-tidy added: 120, removed: 49, total 71
@@ -43,6 +43,7 @@ Checks: >
readability-avoid-const-params-in-decls,
readability-container-size-empty,
readability-duplicate-include,
readability-else-after-return,
readability-identifier-naming,
readability-inconsistent-declaration-parameter-name,
readability-isolate-declaration,
 
css/parser.cpp added: 120, removed: 49, total 71
@@ -125,17 +125,17 @@ public:
std::optional<std::string_view> get() const {
if (empty()) {
return std::nullopt;
} else {
return *token_iter_;
}
 
return *token_iter_;
}
 
std::optional<std::string_view> peek() const {
if (empty() || ((token_iter_ + 1) == cend(tokens_))) {
return std::nullopt;
} else {
return *(token_iter_ + 1);
}
 
return *(token_iter_ + 1);
}
 
Tokenizer &next() {
@@ -161,7 +161,9 @@ std::optional<std::pair<std::string_view, std::optional<std::string_view>>> try_
std::string_view font_size = str.substr(0, loc);
std::string_view line_height = str.substr(loc + 1);
return std::pair(std::move(font_size), std::move(line_height));
} else if (is_absolute_size(str) || is_relative_size(str) || is_length_or_percentage(str)) {
}
 
if (is_absolute_size(str) || is_relative_size(str) || is_length_or_percentage(str)) {
return std::pair(std::move(str), std::nullopt);
}
}
@@ -187,7 +189,9 @@ std::optional<std::string> try_parse_font_style(Tokenizer &tokenizer) {
if (maybe_font_style->starts_with("italic")) {
font_style = *maybe_font_style;
return font_style;
} else if (maybe_font_style->starts_with("oblique")) {
}
 
if (maybe_font_style->starts_with("oblique")) {
font_style = *maybe_font_style;
if (auto maybe_angle = tokenizer.peek()) {
if (maybe_angle->contains("deg")) {
@@ -206,7 +210,9 @@ std::optional<std::string_view> try_parse_font_weight(Tokenizer &tokenizer) {
if (auto maybe_font_weight = tokenizer.get()) {
if (is_weight(*maybe_font_weight)) {
return *maybe_font_weight;
} else if (auto maybe_int = to_int(*maybe_font_weight)) {
}
 
if (auto maybe_int = to_int(*maybe_font_weight)) {
if (*maybe_int >= 1 && *maybe_int <= 1000) {
return *maybe_font_weight;
}
@@ -804,7 +810,9 @@ void Parser::expand_font(Declarations &declarations, std::string_view value) {
}
// Lets break here since font size and family should be last
break;
} else if (auto maybe_font_style = try_parse_font_style(tokenizer)) {
}
 
if (auto maybe_font_style = try_parse_font_style(tokenizer)) {
font_style = *maybe_font_style;
} else if (auto maybe_font_weight = try_parse_font_weight(tokenizer)) {
font_weight = *maybe_font_weight;
 
css2/tokenizer.cpp added: 120, removed: 49, total 71
@@ -223,7 +223,9 @@ void Tokenizer::run() {
if (is_ident_code_point(*c)) {
temporary_buffer_ += *c;
continue;
} else if (*c == '\\') {
}
 
if (*c == '\\') {
// TODO(mkiael): Handle escaped code point
std::terminate();
}
@@ -243,7 +245,9 @@ void Tokenizer::run() {
if (is_ident_code_point(*c)) {
temporary_buffer_ += *c;
continue;
} else if (*c == '\\') {
}
 
if (*c == '\\') {
// TODO(mkiael): Handle escaped code point
std::terminate();
}
 
style/styled_node.cpp added: 120, removed: 49, total 71
@@ -138,16 +138,22 @@ std::optional<gfx::Color> try_from_hex_chars(std::string_view hex_chars) {
if (hex_chars.length() == 6) {
std::from_chars(hex_chars.data(), hex_chars.data() + hex_chars.size(), hex, /*base*/ 16);
return gfx::Color::from_rgb(hex);
} else if (hex_chars.length() == 3) {
}
 
if (hex_chars.length() == 3) {
std::ostringstream ss;
ss << hex_chars[0] << hex_chars[0] << hex_chars[1] << hex_chars[1] << hex_chars[2] << hex_chars[2];
auto expanded = std::move(ss).str();
std::from_chars(expanded.data(), expanded.data() + expanded.size(), hex, /*base*/ 16);
return gfx::Color::from_rgb(hex);
} else if (hex_chars.length() == 8) {
}
 
if (hex_chars.length() == 8) {
std::from_chars(hex_chars.data(), hex_chars.data() + hex_chars.size(), hex, /*base*/ 16);
return gfx::Color::from_rgba(hex);
} else if (hex_chars.length() == 4) {
}
 
if (hex_chars.length() == 4) {
std::ostringstream ss;
ss << hex_chars[0] << hex_chars[0] << hex_chars[1] << hex_chars[1] << hex_chars[2] << hex_chars[2]
<< hex_chars[3] << hex_chars[3];
@@ -299,13 +305,19 @@ std::string_view StyledNode::get_raw_property(css::PropertyId property) const {
}
 
return initial_values.at(property);
} else if (it->second == "initial") {
}
 
if (it->second == "initial") {
// https://developer.mozilla.org/en-US/docs/Web/CSS/initial
return initial_values.at(property);
} else if (it->second == "inherit") {
}
 
if (it->second == "inherit") {
// https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
return get_parent_raw_property(*this, property);
} else if (it->second == "currentcolor") {
}
 
if (it->second == "currentcolor") {
// https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor_keyword
// If the "color" property has the value "currentcolor", treat it as "inherit".
if (it->first == css::PropertyId::Color) {
@@ -327,23 +339,41 @@ BorderStyle StyledNode::get_border_style_property(css::PropertyId property) cons
 
if (raw == "none") {
return BorderStyle::None;
} else if (raw == "hidden") {
}
 
if (raw == "hidden") {
return BorderStyle::Hidden;
} else if (raw == "dotted") {
}
 
if (raw == "dotted") {
return BorderStyle::Dotted;
} else if (raw == "dashed") {
}
 
if (raw == "dashed") {
return BorderStyle::Dashed;
} else if (raw == "solid") {
}
 
if (raw == "solid") {
return BorderStyle::Solid;
} else if (raw == "double") {
}
 
if (raw == "double") {
return BorderStyle::Double;
} else if (raw == "groove") {
}
 
if (raw == "groove") {
return BorderStyle::Groove;
} else if (raw == "ridge") {
}
 
if (raw == "ridge") {
return BorderStyle::Ridge;
} else if (raw == "inset") {
}
 
if (raw == "inset") {
return BorderStyle::Inset;
} else if (raw == "outset") {
}
 
if (raw == "outset") {
return BorderStyle::Outset;
}
 
@@ -366,9 +396,13 @@ DisplayValue StyledNode::get_display_property() const {
auto raw = get_raw_property(css::PropertyId::Display);
if (raw == "none") {
return DisplayValue::None;
} else if (raw == "inline") {
}
 
if (raw == "inline") {
return DisplayValue::Inline;
} else if (raw == "block") {
}
 
if (raw == "block") {
return DisplayValue::Block;
}
 
@@ -380,9 +414,13 @@ FontStyle StyledNode::get_font_style_property() const {
auto raw = get_raw_property(css::PropertyId::FontStyle);
if (raw == "normal") {
return FontStyle::Normal;
} else if (raw == "italic") {
}
 
if (raw == "italic") {
return FontStyle::Italic;
} else if (raw == "oblique") {
}
 
if (raw == "oblique") {
return FontStyle::Oblique;
}
 
@@ -394,13 +432,21 @@ std::vector<TextDecorationLine> StyledNode::get_text_decoration_line_property()
auto into = [](std::string_view v) -> std::optional<TextDecorationLine> {
if (v == "none") {
return TextDecorationLine::None;
} else if (v == "underline") {
}
 
if (v == "underline") {
return TextDecorationLine::Underline;
} else if (v == "overline") {
}
 
if (v == "overline") {
return TextDecorationLine::Overline;
} else if (v == "line-through") {
}
 
if (v == "line-through") {
return TextDecorationLine::LineThrough;
} else if (v == "blink") {
}
 
if (v == "blink") {
return TextDecorationLine::Blink;
}
 
 
url/url.cpp added: 120, removed: 49, total 71
@@ -203,7 +203,9 @@ std::string blob_url_create(Origin const &origin) {
std::string Host::serialize() const {
if (type == HostType::Ip4Addr) {
return util::ipv4_serialize(std::get<std::uint32_t>(data));
} else if (type == HostType::Ip6Addr) {
}
 
if (type == HostType::Ip6Addr) {
return "[" + util::ipv6_serialize(std::get<2>(data)) + "]";
}
 
@@ -294,17 +296,17 @@ Origin Url::origin() const {
 
return path_url->origin();
}
 
// Return a tuple origin
else if (scheme == "ftp" || scheme == "http" || scheme == "https" || scheme == "ws" || scheme == "wss") {
if (scheme == "ftp" || scheme == "http" || scheme == "https" || scheme == "ws" || scheme == "wss") {
// These schemes all require a host in a valid URL
assert(host.has_value());
 
return Origin{scheme, *host, port, std::nullopt};
}
 
// Return a new opaque origin
else {
return Origin{"", Host{}, std::nullopt, std::nullopt, true};
}
return Origin{"", Host{}, std::nullopt, std::nullopt, true};
}
 
void UrlParser::validation_error(ValidationError err) const {
@@ -562,13 +564,17 @@ void UrlParser::state_scheme() {
 
// https://url.spec.whatwg.org/#no-scheme-state
void UrlParser::state_no_scheme() {
if (auto c = peek(); !base_.has_value() || (base_->has_opaque_path() && c != '#')) {
auto c = peek();
 
if (!base_.has_value() || (base_->has_opaque_path() && c != '#')) {
validation_error(ValidationError::MissingSchemeNonRelativeUrl);
 
state_ = ParserState::Failure;
 
return;
} else if (base_->has_opaque_path() && c == '#') {
}
 
if (base_->has_opaque_path() && c == '#') {
url_.scheme = base_->scheme;
url_.path = base_->path;
url_.query = base_->query;
@@ -796,7 +802,9 @@ void UrlParser::state_host() {
state_ = ParserState::Failure;
 
return;
} else if (state_override_.has_value() && buffer_.empty()
}
 
if (state_override_.has_value() && buffer_.empty()
&& (url_.includes_credentials() || url_.port.has_value())) {
state_ = ParserState::Terminate;
 
@@ -1597,7 +1605,9 @@ std::optional<std::array<std::uint16_t, 8>> UrlParser::parse_ipv6(std::string_vi
}
 
break;
} else if (pointer < input.size() && input[pointer] == ':') {
}
 
if (pointer < input.size() && input[pointer] == ':') {
pointer++;
 
if (pointer >= input.size()) {
 
util/string.h added: 120, removed: 49, total 71
@@ -199,7 +199,9 @@ inline std::string ipv6_serialize(std::span<std::uint16_t const, 8> addr) {
for (std::size_t i = 0; i < 8; i++) {
if (ignore0 && addr[i] == 0) {
continue;
} else if (ignore0) {
}
 
if (ignore0) {
ignore0 = false;
}