Skip to content
Closed
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
4 changes: 2 additions & 2 deletions examples/vue-code-file/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = {
{
files: ['*.js', '*.vue'],
parser: 'vue-eslint-parser',
processor: '@graphql-eslint/graphql',
extends: ['eslint:recommended'],
processor: '@graphql-eslint/graphql-vue',
extends: ['eslint:recommended','plugin:vue/base'],
env: {
es6: true,
},
Expand Down
1 change: 1 addition & 0 deletions examples/vue-code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@graphql-eslint/eslint-plugin": "workspace:*",
"@vue/compiler-sfc": "3.3.4",
"eslint": "8.38.0",
"eslint-plugin-vue": "9.14.1",
"vue-eslint-parser": "9.3.0"
}
}
1 change: 1 addition & 0 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"graphql"
],
"peerDependencies": {
"eslint-plugin-vue": "9.14.1",
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { processor } from './processor.js';
import { processor, processorWithVue } from './processor.js';

export { parseForESLint } from './parser.js';
export { rules } from './rules/index.js';
export * from './testkit.js';
export * from './types.js';
export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './utils.js';

export const processors = { graphql: processor };
export const processors = { graphql: processor, 'graphql-vue': processorWithVue };

export { configs } from './configs/index.js';
export { flatConfigs } from './flat-configs.js';
34 changes: 34 additions & 0 deletions packages/plugin/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,37 @@ export const processor: Linter.Processor<Block | string> = {
return result.sort((a, b) => a.line - b.line || a.column - b.column);
},
};

let vueProcessors: Record<string, Linter.Processor<Block | string>>;

export const processorWithVue: Linter.Processor<Block | string> = {
// Get supportsAutofix and preprocess from the normal processor
...processor,

postprocess(messages, filePath) {
if (messages.length > 0) {
// try to load the vue plugin
if (vueProcessors === undefined) {
try {
vueProcessors = require('eslint-plugin-vue').processors;
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
vueProcessors = {};
}
}

// If we have a vue processor, pass it the last element that contains the
// full SFC code for processing
if (vueProcessors['.vue']?.postprocess !== undefined) {
const last = messages.length - 1;
messages[last] = vueProcessors['.vue'].postprocess([messages[last]], filePath);
}

// And pass everything to the graphql processor
return processor.postprocess!(messages, filePath);
} else {
return messages.flat();
}
},
};