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

[WIP] - Update Eslint Configuartion Strategy #50

Open
wants to merge 2 commits into
base: master
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
39 changes: 39 additions & 0 deletions ui.apps/src/main/webpack.core/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const CONFIG_WEBPACK = require('./internals/webpack.config.js');

module.exports = {
// Optional: Replace `eslint:recommended` with `eslint-config-infield` and run
// `npm install --save-dev eslint-config-infield` for stricter linting rules
extends: "eslint:recommended",
env: {
browser: true,
es6: true,
node: true,
},
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
},
settings: {
// This prevents `no-unused-vars` and `import/no-unresolved` from being thrown
// when modules are imported that are defined in Webpack but not correctly
// resolved by `eslint-plugin-import`. Note that `eslint-plugin-import` can
// be defined directly in this project's package.json but it can also be an
// dependency of an extended ESLint configuration.
'import/resolver': {
node: {
paths: (CONFIG_WEBPACK.resolve && CONFIG_WEBPACK.resolve.modules) || [],
},
},
},

// If you want to define variables that are available across various processed JavaScript
// files, define them here. More details: http://eslint.org/docs/user-guide/configuring#specifying-globals
globals: {
$: true,
Granite: true,
},

rules: {
"no-console" : 1, // 0 = off, 1 = warn, 2 = error
}
}
26 changes: 3 additions & 23 deletions ui.apps/src/main/webpack.core/internals/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
const merge = require('merge');
const CONFIG = require('./../../webpack.project');
const CONFIG_WEBPACK = require('./webpack.config.js');
const CONFIG = require('../../webpack.project');
const path = require('path');

const ESLINT_DEFAULT = {
env: {
browser: true,
es6: true,
node: true,
},
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
},
settings: {
// This prevents `no-unused-vars` and `import/no-unresolved` from being thrown
// when modules are imported that are defined in Webpack but not correctly
// resolved by `eslint-plugin-import`. Note that `eslint-plugin-import` can
// be defined directly in this project's package.json but it can also be an
// dependency of an extended ESLint configuration.
'import/resolver': {
node: {
paths: (CONFIG_WEBPACK.resolve && CONFIG_WEBPACK.resolve.modules) || [],
},
},
},
extends: path.resolve(__dirname, '../.eslintrc.js'),
};

module.exports = merge.recursive(true, ESLINT_DEFAULT, CONFIG.eslint);
15 changes: 1 addition & 14 deletions ui.apps/src/main/webpack.project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,7 @@ const WEBPACK = {
* as strict as possible.
*/
const ESLINT = {
// Optional: Replace `eslint:recommended` with `eslint-config-infield` and run
// `npm install --save-dev eslint-config-infield` for stricter linting rules
extends: "eslint:recommended",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I purposefully placed those few lines into webpack.project so users of this Webpack setup have it easy to adjust the ESLint config in the right place. If this part gets moved into webpack.core, I suspect that people will modify the file in the webpack.core folder directly instead of making the effort of overriding the code via webpack.project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree with you and I think you are correct. After I submitted this PR, I was looking into elegant ways to have a base config in webpack.core which is extended in webpack.project.

I also think it's rare for a company to need different ESLint rules for different projects. If that is needed, then a developer could create a new project-name/.eslintrc.js/json file which extends the default.

Thank you for reviewing this Kevin! Your feedback is really appreciated. This PR isn't done, and I should have marked it as a work in progress [WIP].


// If you want to define variables that are available across various processed JavaScript
// files, define them here. More details: http://eslint.org/docs/user-guide/configuring#specifying-globals
globals: {
$: true,
Granite: true,
},

rules: {
"no-console": "off",
},
// You can override or extend the default ESLINT configuration here
};

/**
Expand Down