-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathprocessor_options.js
33 lines (31 loc) · 1.78 KB
/
processor_options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const processor_options = {};
// find Linter instance
const linter_paths = Object.keys(require.cache).filter(path => path.endsWith('/eslint/lib/linter/linter.js') || path.endsWith('\\eslint\\lib\\linter\\linter.js'));
if (!linter_paths.length) {
throw new Error('Could not find ESLint Linter in require cache');
}
// There may be more than one instance of the linter when we're in a workspace with multiple directories.
// We first try to find the one that's inside the same node_modules directory as this plugin.
// If that can't be found for some reason, we assume the one we want is the last one in the array.
const current_node_modules_path = __dirname.replace(/(?<=[/\\]node_modules[/\\]).*$/, '');
const linter_path = linter_paths.find(path => path.startsWith(current_node_modules_path)) || linter_paths.pop();
const { Linter } = require(linter_path);
// patch Linter#verify
const { verify } = Linter.prototype;
Linter.prototype.verify = function(code, config, options) {
// fetch settings
const settings = config && (typeof config.extractConfig === 'function' ? config.extractConfig(options.filename) : config).settings || {};
processor_options.custom_compiler = settings['svelte3/compiler'];
processor_options.ignore_warnings = settings['svelte3/ignore-warnings'];
processor_options.ignore_styles = settings['svelte3/ignore-styles'];
processor_options.compiler_options = settings['svelte3/compiler-options'];
processor_options.named_blocks = settings['svelte3/named-blocks'];
processor_options.typescript =
settings['svelte3/typescript'] === true
? require('typescript')
: typeof settings['svelte3/typescript'] === 'function'
? settings['svelte3/typescript']()
: settings['svelte3/typescript'];
// call original Linter#verify
return verify.call(this, code, config, options);
};