Skip to content

Commit

Permalink
setup command
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Apr 25, 2024
1 parent 481080d commit 2b49ac0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
1 change: 0 additions & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ gleam = ">= 1.0.0"
[dependencies]
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
glance = ">= 0.8.2 and < 1.0.0"
glance_printer = ">= 1.1.0 and < 2.0.0"
simplifile = ">= 1.7.0 and < 2.0.0"
filepath = ">= 1.0.0 and < 2.0.0"
tom = ">= 0.3.0 and < 1.0.0"
Expand Down
3 changes: 0 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ packages = [
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
{ name = "birdie", version = "1.1.2", build_tools = ["gleam"], requirements = ["argv", "filepath", "glance", "gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "justin", "rank", "simplifile", "trie_again"], otp_app = "birdie", source = "hex", outer_checksum = "F9666AEB5F6EDFAE6ADF9DFBF10EF96A4EDBDDB84B854C29B9A3F615A6436311" },
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
{ name = "glam", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "02E0311862B9669C3E8CE73FA5A95D8FA457C6ACB48D95FBE808ABFAE0A1CEB0" },
{ name = "glance", version = "0.8.2", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "ACF09457E8B564AD7A0D823DAFDD326F58263C01ACB0D432A9BEFDEDD1DA8E73" },
{ name = "glance_printer", version = "1.1.0", build_tools = ["gleam"], requirements = ["glam", "glance", "gleam_stdlib"], otp_app = "glance_printer", source = "hex", outer_checksum = "3140D4DD3F6C9119C60F2BA994F728D04E56014498A9C6C994814003EA115DE7" },
{ name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" },
{ name = "gleam_community_colour", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "795964217EBEDB3DA656F5EB8F67D7AD22872EB95182042D3E7AFEF32D3FD2FE" },
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" },
Expand All @@ -27,7 +25,6 @@ packages = [
birdie = { version = ">= 1.1.2 and < 2.0.0" }
filepath = { version = ">= 1.0.0 and < 2.0.0" }
glance = { version = ">= 0.8.2 and < 1.0.0" }
glance_printer = { version = ">= 1.1.0 and < 2.0.0" }
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
simplifile = { version = ">= 1.7.0 and < 2.0.0" }
Expand Down
36 changes: 16 additions & 20 deletions src/code_review.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import gleam/result

// RUNNING THE LINTER ----------------------------------------------------------

pub fn main() -> Nil {
case run(on: project.root()) {
pub fn main(rules: List(Rule)) -> Nil {
case run(on: project.root(), with_rules: rules) {
Ok(rule_errors) ->
list.each(rule_errors, fn(rule_error) {
rule.pretty_print_error(rule_error)
Expand All @@ -33,15 +33,11 @@ pub fn main() -> Nil {

/// Run the linter for a project at the given path.
///
fn run(on project_root: String) -> Result(List(rule.Error), project.Error) {
fn run(
on project_root: String,
with_rules rules: List(Rule),
) -> Result(List(rule.Error), project.Error) {
use knowledge_base <- result.try(project.read(project_root))
let rules = [
no_panic.rule(),
no_unnecessary_string_concatenation.rule(),
no_trailing_underscore.rule(),
no_deprecated.rule(),
]

Ok(visit(knowledge_base, rules))
}

Expand Down Expand Up @@ -160,11 +156,11 @@ fn do_visit_expressions(
visit_statements(rules, statements)
}
glance.RecordUpdate(
module: _,
constructor: _,
record: record,
fields: fields,
) -> {
module: _,
constructor: _,
record: record,
fields: fields,
) -> {
let new_rules = do_visit_expressions(rules, record)

use acc_rules, #(_, expr) <- list.fold(fields, new_rules)
Expand All @@ -182,11 +178,11 @@ fn do_visit_expressions(
do_visit_expressions(rules, expr)
}
glance.FnCapture(
label: _,
function: function,
arguments_before: arguments_before,
arguments_after: arguments_after,
) -> {
label: _,
function: function,
arguments_before: arguments_before,
arguments_after: arguments_after,
) -> {
list.fold(
list.append(arguments_before, arguments_after),
rules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fn expression_visitor(
)

glance.BinaryOperator(
glance.Concatenate,
glance.String(_),
glance.String(_),
) -> #(
glance.Concatenate,
glance.String(_),
glance.String(_),
) -> #(
[
rule.error(
at: context.current_location,
Expand Down
31 changes: 31 additions & 0 deletions src/code_review/setup.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import filepath
import simplifile

const review_file_name = "review.gleam"

const init_setup_src = "
import code_review
import code_review/rules/no_panic
import code_review/rules/no_unnecessary_string_concatenation
import code_review/rules/no_trailing_underscore
import code_review/rules/no_deprecated
pub fn main() {
let rules = [
no_panic.rule(),
no_unnecessary_string_concatenation.rule(),
no_trailing_underscore.rule(),
no_deprecated.rule(),
]
code_review.main(rules)
}
"

pub fn main() {
let assert Ok(curr_dir) = simplifile.current_directory()
let assert Ok(_) =
simplifile.write(
filepath.join(curr_dir, "test/" <> review_file_name),
init_setup_src,
)
}

0 comments on commit 2b49ac0

Please sign in to comment.