Skip to content

Commit

Permalink
Fixed an issue where content was clears by autofix (#32)
Browse files Browse the repository at this point in the history
Fixed an issue where content was clears by autofix
  • Loading branch information
ntwb committed Dec 29, 2019
2 parents f2c9402 + 7fe5ebf commit 1a07e95
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/stylelint-vscode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ module.exports = async function stylelintVSCode(...args) {
...priorOptions,
config: {
rules: {},
},
fix: false,
}
}),
);
}
Expand Down
40 changes: 40 additions & 0 deletions lib/stylelint-vscode/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,43 @@ const what: string = "is this";

t.end();
});

test('stylelintVSCode() with autofix', async (t) => {
t.plan(3);

(async () => {
t.deepEqual(
await stylelintVSCode(new Document(null, 'css', 'a\n{\ncolor:red;\n}'), {
config: { rules: { indentation: [2] } },
fix: true
})
.then(r=>r.output),
'a\n{\n color:red;\n}',
'The autofix should work properly if configs are defined.',
);
})();

(async () => {
t.deepEqual(
await stylelintVSCode(new Document('no-rules.css', 'css', 'a {'), {
config: {},
fix: true
})
.then(r=>r.output),
'a {}',
'The autofix should only work properly for syntax errors if no rules are defined.'
);
})();

(async () => {
t.deepEqual(
await stylelintVSCode(new Document('no-rules.js', 'javascript', '"a"'), {
config: {},
fix: true
})
.then(r=>r.output),
'"a"',
'The JS file autofix should not change the content if no rules are defined.'
);
})();
});

0 comments on commit 1a07e95

Please sign in to comment.