Skip to content

Commit c62a6c6

Browse files
committed
Trim modeline when checking it
1 parent b2287cc commit c62a6c6

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next
44
- Fixed file extensions with multiple delimiters not being prioritised over basic extensions.
5+
- Fixed modeline checking not trimming comments from the first line.
56

67
## 2.5.1
78
*2022-06-26*

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ async function analyse(input?: string | string[], opts: T.Options = {}): Promise
185185
// Check for interpreter match
186186
const matchesInterpretor = data.interpreters?.some(interpreter => firstLine!.match(`\\b${interpreter}\\b`));
187187
// Check modeline declaration
188-
const matchesLang = firstLine!.toLowerCase().match(langMatcher(lang));
189-
const matchesAlias = data.aliases?.some(lang => firstLine!.toLowerCase().match(langMatcher(lang)));
188+
const modelineText = firstLine!.toLowerCase().replace(/^.*-\*-(.+)-\*-.*$/, '$1');
189+
const matchesLang = modelineText.match(langMatcher(lang));
190+
const matchesAlias = data.aliases?.some(lang => modelineText.match(langMatcher(lang)));
190191
// Add language
191192
const interpretorCheck = opts.checkShebang && matchesInterpretor;
192193
const modelineCheck = opts.checkModeline && (matchesLang || matchesAlias);

test/unit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async function unitTest() {
5252
await test(['emacs_cs', '# -*- c# -*-'], ['files', 'C#']);
5353
await test(['vim_sh', '# vim: filetype=sh'], ['files', 'Shell']);
5454
await test(['vim_ruby', '# vim: syntax = ruby'], ['files', 'Ruby']);
55+
await test(['XCompose', '# for Emacs: -*- coding: utf-8 -*-'], ['files', 'XCompose'])
5556
desc('heuristics');
5657
await test(['c-sharp.cs', 'namespace example {} // empty'], ['files', 'C#']);
5758
await test(['smalltalk.cs', '!interface methodsFor: instance'], ['files', 'Smalltalk']);

0 commit comments

Comments
 (0)