mirror of
https://github.com/mirego/accent.git
synced 2024-09-11 10:55:28 +03:00
Update gleam and use latest regex module
This commit is contained in:
parent
cd92e2f79a
commit
dd45a74f75
@ -22,7 +22,7 @@ RUN npm ci --no-audit --no-color && \
|
||||
#
|
||||
# Build Gleam modules
|
||||
#
|
||||
FROM gleamlang/gleam:0.11.0 as gleam-builder
|
||||
FROM gleamlang/gleam:0.11.2 as gleam-builder
|
||||
WORKDIR /opt/build
|
||||
COPY gleam.toml .
|
||||
COPY rebar.config .
|
||||
|
@ -1,6 +1,6 @@
|
||||
import gleam/bool
|
||||
import gleam/regex
|
||||
import gleam/option.{None}
|
||||
import lint/helpers/regex.{Match, Nomatch}
|
||||
import lint/types.{Entry, FirstLetterCase}
|
||||
|
||||
fn message(text) {
|
||||
@ -8,17 +8,13 @@ fn message(text) {
|
||||
}
|
||||
|
||||
fn starts_with_letter(text) {
|
||||
case regex.match(text, "^\[a-zA-Z\]", []) {
|
||||
Match(_) -> True
|
||||
_ -> False
|
||||
}
|
||||
let Ok(re) = regex.from_string("a")
|
||||
regex.check(re, text)
|
||||
}
|
||||
|
||||
fn starts_with_capitalized_letter(text) {
|
||||
case regex.match(text, "^\[A-Z\]", []) {
|
||||
Match(_) -> True
|
||||
_ -> False
|
||||
}
|
||||
let Ok(re) = regex.from_string("^\[A-Z\]")
|
||||
regex.check(re, text)
|
||||
}
|
||||
|
||||
pub fn applicable(entry: Entry) {
|
||||
|
@ -3,8 +3,8 @@ import gleam/bool
|
||||
import gleam/atom
|
||||
import gleam/list
|
||||
import gleam/option.{None}
|
||||
import gleam/regex
|
||||
import lint/helpers/format
|
||||
import lint/helpers/regex.{Match, Nomatch}
|
||||
import lint/types.{Entry, PlaceholderCount}
|
||||
|
||||
fn message(entry: Entry) {
|
||||
@ -15,9 +15,9 @@ fn message(entry: Entry) {
|
||||
}
|
||||
|
||||
fn match_placeholders(text) {
|
||||
let placeholder_regex = "(\{\{\\w+\}\})|(%\{\\w+\})"
|
||||
let Ok(placeholder_regex) = regex.from_string("(\{\{\\w+\}\})|(%\{\\w+\})")
|
||||
|
||||
regex.match(text, placeholder_regex, [atom.create_from_string("global")])
|
||||
regex.scan(placeholder_regex, text)
|
||||
}
|
||||
|
||||
pub fn applicable(entry: Entry) {
|
||||
@ -25,17 +25,11 @@ pub fn applicable(entry: Entry) {
|
||||
}
|
||||
|
||||
pub fn check(entry: Entry) {
|
||||
let value_placeholders = match_placeholders(entry.value)
|
||||
let master_placeholders = match_placeholders(entry.master_value)
|
||||
let master_matches = match_placeholders(entry.master_value)
|
||||
let value_matches = match_placeholders(entry.value)
|
||||
|
||||
case tuple(master_placeholders, value_placeholders) {
|
||||
tuple(Match(_), Nomatch) -> [message(entry)]
|
||||
tuple(Nomatch, Match(_)) -> [message(entry)]
|
||||
tuple(Match(master_matches), Match(value_matches)) ->
|
||||
case list.length(master_matches) == list.length(value_matches) {
|
||||
True -> []
|
||||
False -> [message(entry)]
|
||||
}
|
||||
_ -> []
|
||||
case list.length(master_matches) == list.length(value_matches) {
|
||||
True -> []
|
||||
False -> [message(entry)]
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import gleam/io
|
||||
import gleam/bool
|
||||
import gleam/string
|
||||
import gleam/option.{None}
|
||||
import lint/helpers/regex.{Match, Nomatch}
|
||||
import gleam/regex
|
||||
import lint/types.{Entry, SameTrailingCharacter}
|
||||
|
||||
pub fn applicable(entry: Entry) {
|
||||
@ -10,16 +10,11 @@ pub fn applicable(entry: Entry) {
|
||||
}
|
||||
|
||||
pub fn check(entry: Entry) {
|
||||
let master_with_trailing = regex.match(entry.master_value, "(\\.|:)$", [])
|
||||
let value_with_trailing = regex.match(entry.value, "(\\.|:)$", [])
|
||||
let Ok(re) = regex.from_string("(\\.|:)$")
|
||||
let master_with_trailing = regex.check(re, entry.master_value)
|
||||
let value_with_trailing = regex.check(re, entry.value)
|
||||
|
||||
let mismatch = case tuple(master_with_trailing, value_with_trailing) {
|
||||
tuple(Match(_), Nomatch) -> True
|
||||
tuple(Nomatch, Match(_)) -> True
|
||||
_ -> False
|
||||
}
|
||||
|
||||
case mismatch {
|
||||
case master_with_trailing != value_with_trailing {
|
||||
True -> {
|
||||
let value_trailing_character = string.slice(entry.value, -1, 1)
|
||||
let master_trailing_character = string.slice(entry.master_value, -1, 1)
|
||||
|
@ -1,10 +1,9 @@
|
||||
import gleam/bool
|
||||
import gleam/string
|
||||
import gleam/atom
|
||||
import gleam/list
|
||||
import gleam/option.{None}
|
||||
import gleam/regex
|
||||
import lint/helpers/format
|
||||
import lint/helpers/regex.{Match, Nomatch}
|
||||
import lint/types.{Entry, URLCount}
|
||||
|
||||
fn message(entry: Entry) {
|
||||
@ -12,9 +11,9 @@ fn message(entry: Entry) {
|
||||
}
|
||||
|
||||
fn match_url(text) {
|
||||
let url_regex = "https?://([a-z0-9]+\\.)?[a-z0-9]+\\."
|
||||
let Ok(url_regex) = regex.from_string("https?://([a-z0-9]+\\.)?[a-z0-9]+\\.")
|
||||
|
||||
regex.match(text, url_regex, [atom.create_from_string("global")])
|
||||
regex.scan(url_regex, text)
|
||||
}
|
||||
|
||||
pub fn applicable(entry: Entry) {
|
||||
@ -22,17 +21,11 @@ pub fn applicable(entry: Entry) {
|
||||
}
|
||||
|
||||
pub fn check(entry: Entry) {
|
||||
let value_trailing = match_url(entry.value)
|
||||
let master_trailing = match_url(entry.master_value)
|
||||
let master_matches = match_url(entry.master_value)
|
||||
let value_matches = match_url(entry.value)
|
||||
|
||||
case tuple(master_trailing, value_trailing) {
|
||||
tuple(Match(_), Nomatch) -> [message(entry)]
|
||||
tuple(Nomatch, Match(_)) -> [message(entry)]
|
||||
tuple(Match(master_matches), Match(value_matches)) ->
|
||||
case list.length(master_matches) == list.length(value_matches) {
|
||||
True -> []
|
||||
False -> [message(entry)]
|
||||
}
|
||||
_ -> []
|
||||
case list.length(master_matches) == list.length(value_matches) {
|
||||
True -> []
|
||||
False -> [message(entry)]
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
import gleam/atom.{Atom}
|
||||
|
||||
pub type MatchResult {
|
||||
Match(List(tuple(Int, Int)))
|
||||
Nomatch
|
||||
}
|
||||
|
||||
pub external fn match(String, String, List(Atom)) -> MatchResult =
|
||||
"re" "run"
|
Loading…
Reference in New Issue
Block a user