@@ -12,6 +12,8 @@ let generateRange;
12
12
let tinyPromisify ;
13
13
let stripJSONComments ;
14
14
15
+ const phpEmbeddedScope = 'text.html.php' ;
16
+
15
17
const getConfig = async ( filePath ) => {
16
18
const readFile = tinyPromisify ( fsReadFile ) ;
17
19
const configPath = await findAsync ( dirname ( filePath ) , '.htmlhintrc' ) ;
@@ -25,6 +27,17 @@ const getConfig = async (filePath) => {
25
27
return null ;
26
28
} ;
27
29
30
+ const phpScopedEditor = editor => editor . getCursors ( ) . some ( cursor =>
31
+ cursor . getScopeDescriptor ( ) . getScopesArray ( ) . some ( scope =>
32
+ scope === phpEmbeddedScope ) ) ;
33
+
34
+ const removePHP = str => str . replace ( / < \? (?: p h p | = ) ? (?: [ \s \S ] ) + ?\? > / gi, ( match ) => {
35
+ const newlines = match . match ( / \r ? \n | \r / g) ;
36
+ const newlineCount = newlines ? newlines . length : 0 ;
37
+
38
+ return '\n' . repeat ( newlineCount ) ;
39
+ } ) ;
40
+
28
41
const loadDeps = ( ) => {
29
42
if ( loadDeps . loaded ) {
30
43
return ;
@@ -98,16 +111,11 @@ export default {
98
111
return null ;
99
112
}
100
113
101
- const removePHP = str => str . replace ( / < \? (?: p h p | = ) ? (?: [ \s \S ] ) + ?\? > / gi, ( match ) => {
102
- const newlines = match . match ( / \r ? \n | \r / g) ;
103
- const newlineCount = newlines ? newlines . length : 0 ;
104
-
105
- return '\n' . repeat ( newlineCount ) ;
106
- } ) ;
114
+ const isPhPEditor = phpScopedEditor ( editor ) ;
107
115
108
116
const fileText = editor . getText ( ) ;
109
- const fileTextStripped = removePHP ( fileText ) ;
110
- if ( ! fileTextStripped ) {
117
+ const text = isPhPEditor ? removePHP ( fileText ) : fileText ;
118
+ if ( ! text ) {
111
119
return [ ] ;
112
120
}
113
121
@@ -116,7 +124,7 @@ export default {
116
124
117
125
const ruleset = await getConfig ( filePath ) ;
118
126
119
- const messages = HTMLHint . verify ( fileTextStripped , ruleset || undefined ) ;
127
+ const messages = HTMLHint . verify ( text , ruleset || undefined ) ;
120
128
121
129
if ( editor . getText ( ) !== fileText ) {
122
130
// Editor contents have changed, tell Linter not to update
0 commit comments