Skip to content

Commit

Permalink
Fix crash on named pattern checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Aug 1, 2021
1 parent 7441615 commit 97547ca
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.2
*2021-08-01*
- Fixed crash occurring when checking named patterns.

## 1.4.1
*2021-08-01*
- Added `all` key to `languages` which collates all language data into one object.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linguist-js",
"version": "1.4.1",
"version": "1.4.2",
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
"main": "dist/index.js",
"bin": {
Expand Down
26 changes: 13 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ let { count, results, languages } = linguist(folder, options);
Analyse multiple folders using the syntax `"{folder1,folder2,...}"`.
- `opts` (optional; object):
An object containing analyser options.
- `ignore` (string array):
A list of file path globs to explicitly ignore.
- `keepVendored` (boolean):
Whether to keep vendored files (dependencies, etc) (defaults to `false`).
- `quick` (boolean):
Whether to skip the checking of `.gitattributes` and `.gitignore` files for manual language classifications (defaults to `false`).
Alias for `checkAttributes: false, checkIgnored: false`.
- `checkAttributes` (boolean):
Force the checking of `.gitattributes` files (defaults to `true` unless `quick` is set).
- `checkIgnored` (boolean):
Force the checking of `.gitignore` files (defaults to `true` unless `quick` is set).
- `checkHeuristics` (boolean):
Apply heuristics to ambiguous languages (defaults to `true` unless `quick` is set).
- `ignore` (string array):
A list of file path globs to explicitly ignore.
- `quick` (boolean):
Whether to skip the checking of `.gitattributes` and `.gitignore` files for manual language classifications (defaults to `false`).
Alias for `checkAttributes: false, checkIgnored: false`.
- `keepVendored` (boolean):
Whether to keep vendored files (dependencies, etc) (defaults to `false`).
- `checkAttributes` (boolean):
Force the checking of `.gitattributes` files (defaults to `true` unless `quick` is set).
- `checkIgnored` (boolean):
Force the checking of `.gitignore` files (defaults to `true` unless `quick` is set).
- `checkHeuristics` (boolean):
Apply heuristics to ambiguous languages (defaults to `true` unless `quick` is set).

### Command-line

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export = async function analyse(root = '.', opts: T.Options = {}) {
const patterns: string[] = [];
const normalise = (contents: string | string[]) => patterns.push(...(Array.isArray(contents) ? contents : [contents]));
if (heuristic.pattern) normalise(heuristic.pattern);
if (heuristic.named_pattern) normalise(heuristicsData.namedPatterns[heuristic.named_pattern]);
if (heuristic.named_pattern) normalise(heuristicsData.named_patterns[heuristic.named_pattern]);
// Check file contents and apply heuristic patterns
const fileContent = fs.readFileSync(file, { encoding: 'utf8' });
if (patterns.some(pattern => RegExp(pattern).test(fileContent))) {
Expand Down
2 changes: 1 addition & 1 deletion src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface HeuristicsSchema {
and?: HeuristicsRules[]
}>
}>
namedPatterns: Record<string, string | string[]>
named_patterns: Record<string, string | string[]>
}

export type VendorSchema = string[]

0 comments on commit 97547ca

Please sign in to comment.