Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added preprocess option #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const find_contextual_names = (compiler, node) => {
// extract scripts to lint from component definition
export const preprocess = text => {
const compiler = processor_options.custom_compiler || default_compiler || (default_compiler = require('svelte/compiler'));
if (processor_options.preprocess) {
text = processor_options.preprocess(text)
}
if (processor_options.ignore_styles) {
// wipe the appropriate <style> tags in the file
text = text.replace(/<style(\s[^]*?)?>[^]*?<\/style>/gi, (match, attributes = '') => {
Expand Down
1 change: 1 addition & 0 deletions src/processor_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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.preprocess = settings['svelte3/preprocess'];
processor_options.custom_compiler = settings['svelte3/compiler'];
processor_options.ignore_warnings = settings['svelte3/ignore-warnings'];
processor_options.ignore_styles = settings['svelte3/ignore-styles'];
Expand Down
7 changes: 7 additions & 0 deletions test/samples/preprocess/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
settings: {
'svelte3/preprocess': text => {
return text.replace(/custom-style-tag/g, 'style')
},
},
};
7 changes: 7 additions & 0 deletions test/samples/preprocess/Input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div></div>

<custom-style-tag>
div {
background: black;
}
</custom-style-tag>
1 change: 1 addition & 0 deletions test/samples/preprocess/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]