Skip to content

Commit

Permalink
fixup! feat(valid-style-parse): implemented the rule
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Feb 6, 2025
1 parent 81429ae commit c200b7c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/eslint-plugin-svelte/src/rules/valid-style-parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRule } from '../utils/index.js';
import { getSourceCode } from '../utils/compat.js';
import { getCwd, getSourceCode } from '../utils/compat.js';

export default createRule('valid-style-parse', {
meta: {
Expand All @@ -9,24 +9,23 @@ export default createRule('valid-style-parse', {
recommended: false
},
schema: [],
messages: {
parseError: 'Error parsing style element'
},
messages: {},
type: 'problem'
},
create(context) {
const sourceCode = getSourceCode(context);
if (!sourceCode.parserServices.isSvelte) {
return {};
}
const cwd = `${getCwd(context)}/`;

return {
SvelteStyleElement(node) {
const styleContext = sourceCode.parserServices.getStyleContext!();
if (styleContext.status === 'parse-error') {
context.report({
loc: node.loc,
messageId: 'parseError'
message: `Error parsing style element. Error message: "${styleContext.error.message.replace(cwd, '')}"`
});
}
if (styleContext.status === 'unknown-lang') {
Expand Down

0 comments on commit c200b7c

Please sign in to comment.