diff --git a/.eslintrc.diff.js b/.eslintrc.diff.js new file mode 100644 index 0000000000..42bf8e064f --- /dev/null +++ b/.eslintrc.diff.js @@ -0,0 +1,39 @@ +const path = require('path'); + +// Additional eslint rules specific to the Authoring MFE, which only run on modified files. + +module.exports = { + rules: { + 'no-restricted-imports': ['error', { + patterns: [ + { + // Ban injectIntl() HOC + group: ['@edx/frontend-platform/i18n'], + importNames: ['injectIntl'], + message: "Use 'useIntl' hook instead of injectIntl.", + }, + { + // Ban connect()/mapStateToProps/mapDispatchToProps HOC pattern + group: ['react-redux'], + importNames: ['connect'], + message: "Use 'useDispatch' and 'useSelector' hooks instead of 'connect'.", + }, + // In the near future we will require 'propTypes' to be removed from all modified code too: + // { + // group: ['prop-types'], + // message: 'Use TypeScript types instead of propTypes.', + // }, + ], + }], + // Ban 'defaultProps' from any modified code. + 'react/require-default-props': ['error', { functions: 'defaultArguments' }], + }, + settings: { + // Import URLs should be resolved using aliases + 'import/resolver': { + webpack: { + config: path.resolve(__dirname, 'webpack.dev.config.js'), + }, + }, + }, +}; diff --git a/Makefile b/Makefile index 3d705bfb10..ead1322bd6 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ validate: make validate-no-uncommitted-package-lock-changes npm run i18n_extract npm run lint -- --max-warnings 0 + npm run lint:diff npm run types npm run test:ci npm run build diff --git a/package.json b/package.json index cb9806e9f9..19103f1174 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "stylelint": "stylelint \"plugins/**/*.scss\" \"src/**/*.scss\" \"scss/**/*.scss\" --config .stylelintrc.json", "lint": "npm run stylelint && fedx-scripts eslint --ext .js --ext .jsx --ext .ts --ext .tsx .", "lint:fix": "npm run stylelint -- --fix && fedx-scripts eslint --fix --ext .js --ext .jsx --ext .ts --ext .tsx .", + "lint:diff": "git diff --name-only master | grep -E '^src/.*(\\.jsx?$|\\.tsx?)$' | xargs fedx-scripts eslint --config .eslintrc.diff.js", "start": "fedx-scripts webpack-dev-server --progress", "start:with-theme": "paragon install-theme && npm start && npm install", "dev": "PUBLIC_PATH=/authoring/ MFE_CONFIG_API_URL='http://localhost:8000/api/mfe_config/v1' fedx-scripts webpack-dev-server --progress --host apps.local.openedx.io", diff --git a/tsconfig.json b/tsconfig.json index 77abe775a2..9f084436b0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "include": [ "*.js", ".eslintrc.js", + ".eslintrc.diff.js", "src/**/*", "plugins/**/*" ],