diff --git a/packages/@vue/cli-plugin-eslint/ui.js b/packages/@vue/cli-plugin-eslint/ui.js index 85afc380fa..993ff10bb1 100644 --- a/packages/@vue/cli-plugin-eslint/ui.js +++ b/packages/@vue/cli-plugin-eslint/ui.js @@ -11,159 +11,156 @@ module.exports = api => { js: ['.eslintrc.js'], package: 'eslintConfig' }, - onRead: ({ data }) => { - console.log('rules', data.rules) - return { - prompts: [ - { - name: 'vue/attribute-hyphenation', - type: 'list', - message: 'Attribute hyphenation', - group: 'Strongly recommended', - description: 'Enforce attribute naming style in template (`my-prop` or `myProp`)', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/attribute-hyphenation.md', - default: JSON.stringify('off'), - choices: [ - { - name: 'Off', - value: JSON.stringify('off') - }, - { - name: 'Never', - value: JSON.stringify(['error', 'never']) - }, - { - name: 'Always', - value: JSON.stringify(['error', 'always']) - } - ], - value: data.rules && JSON.stringify(data.rules['vue/attribute-hyphenation']) - }, - { - name: 'vue/html-end-tags', - type: 'confirm', - message: 'Template end tags style', - group: 'Strongly recommended', - description: 'End tag on Void elements, end tags and self-closing opening tags', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-end-tags.md', - default: false, - value: data.rules && data.rules['vue/html-end-tags'] === 'error', - filter: input => JSON.stringify(input ? 'error' : 'off') - }, - { - name: 'vue/html-indent', - type: 'list', - message: 'Template indentation', - group: 'Strongly recommended', - description: 'Enforce indentation in template', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-indent.md', - default: JSON.stringify('off'), - choices: [ - { - name: 'Off', - value: JSON.stringify('off') - }, - { - name: 'Tabs', - value: JSON.stringify(['error', 'tabs']) - }, - { - name: '2 spaces', - value: JSON.stringify(['error', 2]) - }, - { - name: '4 spaces', - value: JSON.stringify(['error', 4]) - }, - { - name: '8 spaces', - value: JSON.stringify(['error', 8]) - } - ], - value: data.rules && JSON.stringify(data.rules['vue/html-indent']) - }, - { - name: 'vue/html-self-closing', - type: 'confirm', - message: 'Template tag self-closing style', - group: 'Strongly recommended', - description: 'Self-close any component or non-Void element tags', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-self-closing.md', - default: false, - value: data.rules && data.rules['vue/html-self-closing'] === 'error', - filter: input => JSON.stringify(input ? 'error' : 'off') - }, - { - name: 'vue/require-default-prop', - type: 'confirm', - message: 'Require default in required props', - group: 'Strongly recommended', - description: 'This rule requires default value to be set for each props that are not marked as `required`', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/require-default-prop.md', - default: false, - value: data.rules && data.rules['vue/require-default-prop'] === 'error', - filter: input => JSON.stringify(input ? 'error' : 'off') - }, - { - name: 'vue/require-prop-types', - type: 'confirm', - message: 'Require types for props', - group: 'Strongly recommended', - description: 'In committed code, prop definitions should always be as detailed as possible, specifying at least type(s)', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/require-prop-types.md', - default: false, - value: data.rules && data.rules['vue/require-prop-types'] === 'error', - filter: input => JSON.stringify(input ? 'error' : 'off') - }, - { - name: 'vue/attributes-order', - type: 'confirm', - message: 'Attribute order', - group: 'Recommended', - description: 'This rule aims to enforce ordering of component attributes (the default order is specified in the Vue style guide)', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/attributes-order.md', - default: false, - value: data.rules && data.rules['vue/attributes-order'] === 'error', - filter: input => JSON.stringify(input ? 'error' : 'off') - }, - { - name: 'vue/html-quotes', - type: 'list', - message: 'Attribute quote style', - group: 'Recommended', - description: 'Enforce style of the attribute quotes in templates', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-quotes.md', - default: JSON.stringify('off'), - choices: [ - { - name: 'Off', - value: JSON.stringify('off') - }, - { - name: 'Double quotes', - value: JSON.stringify(['error', 'double']) - }, - { - name: 'Single quotes', - value: JSON.stringify(['error', 'single']) - } - ], - value: data.rules && JSON.stringify(data.rules['vue/html-quotes']) - }, - { - name: 'vue/order-in-components', - type: 'confirm', - message: 'Component options order', - group: 'Recommended', - description: 'This rule aims to enforce ordering of component options (the default order is specified in the Vue style guide)', - link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/order-in-components.md', - default: false, - value: data.rules && data.rules['vue/order-in-components'] === 'error', - filter: input => JSON.stringify(input ? 'error' : 'off') - } - ] - } - }, + onRead: ({ data }) => ({ + prompts: [ + { + name: 'vue/attribute-hyphenation', + type: 'list', + message: 'Attribute hyphenation', + group: 'Strongly recommended', + description: 'Enforce attribute naming style in template (`my-prop` or `myProp`)', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/attribute-hyphenation.md', + default: JSON.stringify('off'), + choices: [ + { + name: 'Off', + value: JSON.stringify('off') + }, + { + name: 'Never', + value: JSON.stringify(['error', 'never']) + }, + { + name: 'Always', + value: JSON.stringify(['error', 'always']) + } + ], + value: data.rules && JSON.stringify(data.rules['vue/attribute-hyphenation']) + }, + { + name: 'vue/html-end-tags', + type: 'confirm', + message: 'Template end tags style', + group: 'Strongly recommended', + description: 'End tag on Void elements, end tags and self-closing opening tags', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-end-tags.md', + default: false, + value: data.rules && data.rules['vue/html-end-tags'] === 'error', + filter: input => JSON.stringify(input ? 'error' : 'off') + }, + { + name: 'vue/html-indent', + type: 'list', + message: 'Template indentation', + group: 'Strongly recommended', + description: 'Enforce indentation in template', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-indent.md', + default: JSON.stringify('off'), + choices: [ + { + name: 'Off', + value: JSON.stringify('off') + }, + { + name: 'Tabs', + value: JSON.stringify(['error', 'tabs']) + }, + { + name: '2 spaces', + value: JSON.stringify(['error', 2]) + }, + { + name: '4 spaces', + value: JSON.stringify(['error', 4]) + }, + { + name: '8 spaces', + value: JSON.stringify(['error', 8]) + } + ], + value: data.rules && JSON.stringify(data.rules['vue/html-indent']) + }, + { + name: 'vue/html-self-closing', + type: 'confirm', + message: 'Template tag self-closing style', + group: 'Strongly recommended', + description: 'Self-close any component or non-Void element tags', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-self-closing.md', + default: false, + value: data.rules && data.rules['vue/html-self-closing'] === 'error', + filter: input => JSON.stringify(input ? 'error' : 'off') + }, + { + name: 'vue/require-default-prop', + type: 'confirm', + message: 'Require default in required props', + group: 'Strongly recommended', + description: 'This rule requires default value to be set for each props that are not marked as `required`', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/require-default-prop.md', + default: false, + value: data.rules && data.rules['vue/require-default-prop'] === 'error', + filter: input => JSON.stringify(input ? 'error' : 'off') + }, + { + name: 'vue/require-prop-types', + type: 'confirm', + message: 'Require types for props', + group: 'Strongly recommended', + description: 'In committed code, prop definitions should always be as detailed as possible, specifying at least type(s)', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/require-prop-types.md', + default: false, + value: data.rules && data.rules['vue/require-prop-types'] === 'error', + filter: input => JSON.stringify(input ? 'error' : 'off') + }, + { + name: 'vue/attributes-order', + type: 'confirm', + message: 'Attribute order', + group: 'Recommended', + description: 'This rule aims to enforce ordering of component attributes (the default order is specified in the Vue style guide)', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/attributes-order.md', + default: false, + value: data.rules && data.rules['vue/attributes-order'] === 'error', + filter: input => JSON.stringify(input ? 'error' : 'off') + }, + { + name: 'vue/html-quotes', + type: 'list', + message: 'Attribute quote style', + group: 'Recommended', + description: 'Enforce style of the attribute quotes in templates', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-quotes.md', + default: JSON.stringify('off'), + choices: [ + { + name: 'Off', + value: JSON.stringify('off') + }, + { + name: 'Double quotes', + value: JSON.stringify(['error', 'double']) + }, + { + name: 'Single quotes', + value: JSON.stringify(['error', 'single']) + } + ], + value: data.rules && JSON.stringify(data.rules['vue/html-quotes']) + }, + { + name: 'vue/order-in-components', + type: 'confirm', + message: 'Component options order', + group: 'Recommended', + description: 'This rule aims to enforce ordering of component options (the default order is specified in the Vue style guide)', + link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/order-in-components.md', + default: false, + value: data.rules && data.rules['vue/order-in-components'] === 'error', + filter: input => JSON.stringify(input ? 'error' : 'off') + } + ] + }), onWrite: ({ api, prompts }) => { api.setData(prompts.reduce((obj, prompt) => { obj[`rules.${prompt.id}`] = api.getAnswer(prompt.id, JSON.parse) diff --git a/packages/@vue/cli-ui/src/graphql-api/connectors/configurations.js b/packages/@vue/cli-ui/src/graphql-api/connectors/configurations.js index 458753cd0e..00017d3654 100644 --- a/packages/@vue/cli-ui/src/graphql-api/connectors/configurations.js +++ b/packages/@vue/cli-ui/src/graphql-api/connectors/configurations.js @@ -24,6 +24,10 @@ function findOne (id, context) { } function findFile (config, context) { + if (!config.files) { + return null + } + if (config.files.package) { const pkg = folders.readPackage(cwd.get(), context) const data = pkg[config.files.package] @@ -59,9 +63,11 @@ function readData (config, context) { return yaml.safeLoad(rawContent) } else if (file.type === 'js') { // TODO + console.warn('JS config read not implemented') } } } + return {} } function writeData ({ config, data }, context) { @@ -79,6 +85,7 @@ function writeData ({ config, data }, context) { rawContent = yaml.safeDump(data) } else if (file.type === 'js') { // TODO + console.warn('JS config write not implemented') } } fs.writeFileSync(file.path, rawContent, { encoding: 'utf8' })