mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Report import lowercase alias
This commit is contained in:
parent
97ed8fdbbd
commit
f81985533c
4 changed files with 51 additions and 6 deletions
|
@ -4987,6 +4987,25 @@ mod test_reporting {
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
lowercase_import_alias,
|
||||||
|
indoc!(
|
||||||
|
r"
|
||||||
|
import svg.Path as path
|
||||||
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
── LOWERCASE ALIAS in tmp/lowercase_import_alias/Test.roc ──────────────────────
|
||||||
|
|
||||||
|
This import is using a lowercase alias:
|
||||||
|
|
||||||
|
4│ import svg.Path as path
|
||||||
|
^^^^
|
||||||
|
|
||||||
|
Module names and aliases must start with an uppercase letter.
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
|
||||||
test_report!(
|
test_report!(
|
||||||
ingested_file_import_ann_syntax_err,
|
ingested_file_import_ann_syntax_err,
|
||||||
indoc!(
|
indoc!(
|
||||||
|
|
|
@ -9,8 +9,7 @@ use crate::blankspace::{
|
||||||
space0_before_optional_after, space0_e, spaces, spaces_around, spaces_before,
|
space0_before_optional_after, space0_e, spaces, spaces_around, spaces_before,
|
||||||
};
|
};
|
||||||
use crate::ident::{
|
use crate::ident::{
|
||||||
integer_ident, lowercase_ident, parse_ident, unqualified_ident, uppercase_ident, Accessor,
|
integer_ident, lowercase_ident, parse_ident, unqualified_ident, Accessor, Ident, Suffix,
|
||||||
Ident, Suffix,
|
|
||||||
};
|
};
|
||||||
use crate::module::module_name_help;
|
use crate::module::module_name_help;
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
|
@ -997,10 +996,20 @@ fn import_as<'a>(
|
||||||
EImport::IndentAs,
|
EImport::IndentAs,
|
||||||
EImport::IndentAlias
|
EImport::IndentAlias
|
||||||
),
|
),
|
||||||
item: loc!(map!(
|
item: then(
|
||||||
specialize_err(|_, pos| EImport::Alias(pos), uppercase_ident()),
|
specialize_err(|_, pos| EImport::Alias(pos), loc!(unqualified_ident())),
|
||||||
ImportAlias::new
|
|_arena, state, _progress, loc_ident| {
|
||||||
))
|
match loc_ident.value.chars().next() {
|
||||||
|
Some(first) if first.is_uppercase() => Ok((
|
||||||
|
MadeProgress,
|
||||||
|
loc_ident.map(|ident| ImportAlias::new(ident)),
|
||||||
|
state,
|
||||||
|
)),
|
||||||
|
Some(_) => Err((MadeProgress, EImport::LowercaseAlias(loc_ident.region))),
|
||||||
|
None => Err((MadeProgress, EImport::Alias(state.pos()))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -534,6 +534,7 @@ pub enum EImport<'a> {
|
||||||
As(Position),
|
As(Position),
|
||||||
IndentAlias(Position),
|
IndentAlias(Position),
|
||||||
Alias(Position),
|
Alias(Position),
|
||||||
|
LowercaseAlias(Region),
|
||||||
IndentExposing(Position),
|
IndentExposing(Position),
|
||||||
Exposing(Position),
|
Exposing(Position),
|
||||||
ExposingListStart(Position),
|
ExposingListStart(Position),
|
||||||
|
|
|
@ -1514,7 +1514,23 @@ fn to_import_report<'a>(
|
||||||
alloc.reflow(" keyword, so I was expecting to see an alias next."),
|
alloc.reflow(" keyword, so I was expecting to see an alias next."),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
|
LowercaseAlias(region) => {
|
||||||
|
let surroundings = Region::new(start, region.end());
|
||||||
|
let region = lines.convert_region(*region);
|
||||||
|
|
||||||
|
let doc = alloc.stack([
|
||||||
|
alloc.reflow(r"This import is using a lowercase alias:"),
|
||||||
|
alloc.region_with_subregion(lines.convert_region(surroundings), region),
|
||||||
|
alloc.reflow(r"Module names and aliases must start with an uppercase letter."),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Report {
|
||||||
|
filename,
|
||||||
|
doc,
|
||||||
|
title: "LOWERCASE ALIAS".to_string(),
|
||||||
|
severity: Severity::RuntimeError,
|
||||||
|
}
|
||||||
|
}
|
||||||
Annotation(problem, pos) => to_type_report(alloc, lines, filename, problem, *pos),
|
Annotation(problem, pos) => to_type_report(alloc, lines, filename, problem, *pos),
|
||||||
Space(problem, pos) => to_space_report(alloc, lines, filename, problem, *pos),
|
Space(problem, pos) => to_space_report(alloc, lines, filename, problem, *pos),
|
||||||
ExposingListStart(_) => todo!(),
|
ExposingListStart(_) => todo!(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue