Skip to content

Commit

Permalink
Merge branch 'main' into language/c
Browse files Browse the repository at this point in the history
  • Loading branch information
spenserblack authored Aug 18, 2023
2 parents f158454 + f0fa463 commit f402c84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions gengo/languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ C:
- cake
- cs
- csx
CMake:
category: programming
color: "#CCCCCC"
matchers:
extensions:
- cmake
filenames:
- CMakeLists.txt
CSS:
category: markup
color: "#AA88AA"
Expand Down Expand Up @@ -156,6 +164,7 @@ JavaScript:
matchers:
extensions:
- js
- jsx
interpreters:
- node
Makefile:
Expand Down Expand Up @@ -271,6 +280,7 @@ TypeScript:
matchers:
extensions:
- ts
- tsx
interpreters:
- deno
Vue:
Expand Down
7 changes: 5 additions & 2 deletions gengo/src/generated.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::GLOB_MATCH_OPTIONS;
use glob::Pattern;
use std::path::Path;

Expand All @@ -17,7 +18,9 @@ impl Generated {
}

fn is_generated_no_read<P: AsRef<Path>>(&self, filepath: P) -> bool {
self.globs.iter().any(|g| g.matches_path(filepath.as_ref()))
self.globs
.iter()
.any(|g| g.matches_path_with(filepath.as_ref(), GLOB_MATCH_OPTIONS))
}

fn is_generated_with_read<P: AsRef<Path>>(&self, _filepath: P, contents: &[u8]) -> bool {
Expand All @@ -33,7 +36,7 @@ impl Generated {
}

fn globs() -> Vec<Pattern> {
["dist/**", "*.min.css", "*.min.js"]
["dist/**", "**/*.min.css", "**/*.min.js"]
.into_iter()
.map(|s| Pattern::new(s).unwrap())
.collect()
Expand Down
9 changes: 8 additions & 1 deletion gengo/src/languages/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use indexmap::IndexSet;
use once_cell::sync::Lazy;
use regex::Regex;

use crate::GLOB_MATCH_OPTIONS;
use std::ffi::{OsStr, OsString};
use std::fmt::Display;
use std::path::Path;
Expand Down Expand Up @@ -74,7 +75,7 @@ impl FilepathPattern {
pub fn matches<P: AsRef<Path>>(&self, filename: P) -> bool {
self.patterns
.iter()
.any(|p| p.matches_path(filename.as_ref()))
.any(|p| p.matches_path_with(filename.as_ref(), GLOB_MATCH_OPTIONS))
}
}

Expand Down Expand Up @@ -153,6 +154,12 @@ mod tests {
assert!(analyzer.matches(filename));
}

#[rstest(pattern, filename, case("Makefile.*", "Makefile.in/foo"))]
fn test_rejects_pattern(pattern: &str, filename: &str) {
let analyzer = FilepathPattern::new(&[pattern.into()]);
assert!(!analyzer.matches(filename));
}

#[test]
fn test_matches_shebang() {
let analyzer = Shebang::new(&["python", "python3"]);
Expand Down
8 changes: 8 additions & 0 deletions gengo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use builder::Builder;
use documentation::Documentation;
use generated::Generated;
use git2::{AttrCheckFlags, AttrValue, Blob, Commit, ObjectType, Repository, Tree};
use glob::MatchOptions;
use indexmap::IndexMap;
pub use languages::analyzer::Analyzers;
use languages::Category;
Expand All @@ -16,6 +17,13 @@ mod generated;
pub mod languages;
mod vendored;

/// Shared match options for consistent behavior.
const GLOB_MATCH_OPTIONS: MatchOptions = MatchOptions {
case_sensitive: true,
require_literal_separator: true,
require_literal_leading_dot: false,
};

/// The main entry point for Gengo.
pub struct Gengo {
repository: Repository,
Expand Down

0 comments on commit f402c84

Please sign in to comment.