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

eslint-setup: Adds logic to create simplified eslintrc.js file. #942

Open
wants to merge 5 commits into
base: eleven
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
1 change: 0 additions & 1 deletion packages/eslint-config/cypress.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
extends: ['.index.js'],
plugins: ['cypress'],
env: {
'cypress/globals': true,
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/jest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['plugin:jest/recommended', './index.js'],
extends: ['plugin:jest/recommended'],
rules: {
'jest/expect-expect': 'off',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/react.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['prettier/react', './index.js'],
extends: ['prettier/react'],
rules: {
'react/jsx-filename-extension': 'off',
'import/extensions': [
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/typescript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['prettier/@typescript', './index.js'],
extends: ['prettier/@typescript'],
overrides: [
{
files: ['**/*.ts?(x)'],
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/vue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['plugin:vue/recommended', 'prettier/vue', './index.js'],
extends: ['plugin:vue/recommended', 'prettier/vue'],
}
38 changes: 38 additions & 0 deletions packages/generator-particle-base/src/generators/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Generator from 'yeoman-generator'
import merge from 'lodash.merge'
import fs from 'fs'
import _ from 'lodash';

import {
Answers,
Expand Down Expand Up @@ -88,6 +89,40 @@ module.exports = class extends Generator {
)
}

/**
* Create eslintrc file
**/

_eslintCompile(configuration: Answers ) {
const { frontendFramework, testingLibraries, hasTypescript } = configuration.options

// Array of all valid eslint-config sub-modules listed in CLI.
const validPackages: string[] = ['react', 'vue', 'cypress', 'jest', 'typescript']

// Array of users CLI selections.
const extend: string[] = [
...frontendFramework,
...testingLibraries,
hasTypescript ? 'typescript' : ''
]

// Filter for valid packages and construct extends array elements.
const elements: string[] = _.filter(
extend, (el)=> validPackages
.includes(el))
.map(el => `\n'@phase2/eslint-config/${el}'`
)

const esModule = `module.exports = {
extends: [
'@phase2/eslint-config', ${elements}
]
}`

fs.writeFileSync(`${process.cwd()}/.eslintrc.js`, esModule)

}

async _promptUser() {
// Initialize storybook
const results: ConfigurationAnswers = await this.prompt(configurationPrompt)
Expand Down Expand Up @@ -115,6 +150,9 @@ module.exports = class extends Generator {
async initializing() {
await this._promptUser()

// Compile eslintrc.js file from user input.
this._eslintCompile(this.configuration)

// All composed generators must be imported following this syntax https://yeoman.io/authoring/composability.html
if (
this.configuration.options.frontendFramework.includes(
Expand Down