mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(parser,linter)!: add ParserReturn::is_flow_language; linter ignore flow error (#7373)
closes #7123
This commit is contained in:
parent
666b6c104c
commit
878189c407
5 changed files with 26 additions and 2 deletions
2
apps/oxlint/fixtures/flow/flow.js
Normal file
2
apps/oxlint/fixtures/flow/flow.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// @flow
|
||||
import { type Node, type ElementRef } from 'react';
|
||||
1
apps/oxlint/fixtures/flow/index.mjs
Normal file
1
apps/oxlint/fixtures/flow/index.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
import './flow.js'
|
||||
|
|
@ -378,6 +378,15 @@ mod test {
|
|||
assert_eq!(result.number_of_errors, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignore_flow() {
|
||||
let args = &["--import-plugin", "fixtures/flow/index.mjs"];
|
||||
let result = test(args);
|
||||
assert_eq!(result.number_of_files, 1);
|
||||
assert_eq!(result.number_of_warnings, 0);
|
||||
assert_eq!(result.number_of_errors, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_allow_all() {
|
||||
let args = &["-A", "all", "fixtures/linter"];
|
||||
|
|
|
|||
|
|
@ -199,7 +199,11 @@ impl Runtime {
|
|||
.parse();
|
||||
|
||||
if !ret.errors.is_empty() {
|
||||
return ret.errors.into_iter().map(|err| Message::new(err, None)).collect();
|
||||
return if ret.is_flow_language {
|
||||
vec![]
|
||||
} else {
|
||||
ret.errors.into_iter().map(|err| Message::new(err, None)).collect()
|
||||
};
|
||||
};
|
||||
|
||||
// Build the module record to unblock other threads from waiting for too long.
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ pub(crate) const MAX_LEN: usize = if std::mem::size_of::<usize>() >= 8 {
|
|||
/// [`program`]: ParserReturn::program
|
||||
/// [`errors`]: ParserReturn::errors
|
||||
/// [`panicked`]: ParserReturn::panicked
|
||||
#[non_exhaustive]
|
||||
pub struct ParserReturn<'a> {
|
||||
/// The parsed AST.
|
||||
///
|
||||
|
|
@ -168,6 +169,9 @@ pub struct ParserReturn<'a> {
|
|||
/// [`program`]: ParserReturn::program
|
||||
/// [`errors`]: ParserReturn::errors
|
||||
pub panicked: bool,
|
||||
|
||||
/// Whether the file is [flow](https://flow.org).
|
||||
pub is_flow_language: bool,
|
||||
}
|
||||
|
||||
/// Parse options
|
||||
|
|
@ -415,10 +419,12 @@ impl<'a> ParserImpl<'a> {
|
|||
};
|
||||
|
||||
self.check_unfinished_errors();
|
||||
let mut is_flow_language = false;
|
||||
let mut errors = vec![];
|
||||
// only check for `@flow` if the file failed to parse.
|
||||
if !self.lexer.errors.is_empty() || !self.errors.is_empty() {
|
||||
if let Some(error) = self.flow_error() {
|
||||
is_flow_language = true;
|
||||
errors.push(error);
|
||||
}
|
||||
}
|
||||
|
|
@ -429,7 +435,7 @@ impl<'a> ParserImpl<'a> {
|
|||
}
|
||||
let irregular_whitespaces =
|
||||
self.lexer.trivia_builder.irregular_whitespaces.into_boxed_slice();
|
||||
ParserReturn { program, errors, irregular_whitespaces, panicked }
|
||||
ParserReturn { program, errors, irregular_whitespaces, panicked, is_flow_language }
|
||||
}
|
||||
|
||||
pub fn parse_expression(mut self) -> std::result::Result<Expression<'a>, Vec<OxcDiagnostic>> {
|
||||
|
|
@ -570,6 +576,7 @@ mod test {
|
|||
let ret = Parser::new(&allocator, source, source_type).parse();
|
||||
assert!(ret.program.is_empty());
|
||||
assert!(ret.errors.is_empty());
|
||||
assert!(!ret.is_flow_language);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -597,6 +604,7 @@ mod test {
|
|||
];
|
||||
for source in sources {
|
||||
let ret = Parser::new(&allocator, source, source_type).parse();
|
||||
assert!(ret.is_flow_language);
|
||||
assert_eq!(ret.errors.len(), 1);
|
||||
assert_eq!(ret.errors.first().unwrap().to_string(), "Flow is not supported");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue