2017-01-23 18:33:09 +01:00
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
// get the path of the js-sdk so we can extend the config
|
|
|
|
// eslint supports loading extended configs by module,
|
|
|
|
// but only if they come from a module that starts with eslint-config-
|
|
|
|
// So we load the filename directly (and it could be in node_modules/
|
|
|
|
// or or ../node_modules/ etc)
|
|
|
|
const matrixJsSdkPath = path.dirname(require.resolve('matrix-js-sdk'));
|
|
|
|
|
2017-01-20 15:08:14 +01:00
|
|
|
module.exports = {
|
|
|
|
parser: "babel-eslint",
|
2017-01-23 18:33:09 +01:00
|
|
|
extends: [matrixJsSdkPath + "/.eslintrc.js"],
|
2017-01-20 15:08:14 +01:00
|
|
|
plugins: [
|
|
|
|
"react",
|
|
|
|
"flowtype",
|
2017-02-16 12:19:00 +01:00
|
|
|
"babel"
|
2017-01-20 15:08:14 +01:00
|
|
|
],
|
2019-02-18 16:36:11 +01:00
|
|
|
globals: {
|
|
|
|
LANGUAGES_FILE: "readonly",
|
|
|
|
},
|
2017-01-20 15:08:14 +01:00
|
|
|
env: {
|
|
|
|
es6: true,
|
|
|
|
},
|
|
|
|
parserOptions: {
|
|
|
|
ecmaFeatures: {
|
|
|
|
jsx: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
2017-02-16 12:19:00 +01:00
|
|
|
// eslint's built in no-invalid-this rule breaks with class properties
|
|
|
|
"no-invalid-this": "off",
|
|
|
|
// so we replace it with a version that is class property aware
|
|
|
|
"babel/no-invalid-this": "error",
|
|
|
|
|
2017-11-16 14:18:58 +01:00
|
|
|
// We appear to follow this most of the time, so let's enforce it instead
|
|
|
|
// of occasionally following it (or catching it in review)
|
|
|
|
"keyword-spacing": "error",
|
|
|
|
|
2017-01-20 15:08:14 +01:00
|
|
|
/** react **/
|
|
|
|
// This just uses the react plugin to help eslint known when
|
|
|
|
// variables have been used in JSX
|
|
|
|
"react/jsx-uses-vars": "error",
|
2017-11-10 17:11:59 +01:00
|
|
|
// Don't mark React as unused if we're using JSX
|
|
|
|
"react/jsx-uses-react": "error",
|
2017-01-20 15:08:14 +01:00
|
|
|
|
|
|
|
// bind or arrow function in props causes performance issues
|
2018-05-02 18:36:29 +02:00
|
|
|
// (but we currently use them in some places)
|
2019-01-22 01:49:48 +01:00
|
|
|
// It's disabled here, but we should using it sparingly.
|
|
|
|
"react/jsx-no-bind": "off",
|
2017-01-20 15:08:14 +01:00
|
|
|
"react/jsx-key": ["error"],
|
|
|
|
|
2018-12-18 16:14:55 +01:00
|
|
|
// Components in JSX should always be defined.
|
|
|
|
"react/jsx-no-undef": "error",
|
|
|
|
|
2017-09-28 11:02:40 +02:00
|
|
|
// Assert no spacing in JSX curly brackets
|
|
|
|
// <Element prop={ consideredError} prop={notConsideredError} />
|
2017-09-28 11:27:03 +02:00
|
|
|
//
|
|
|
|
// https://github.com/yannickcr/eslint-plugin-react/blob/HEAD/docs/rules/jsx-curly-spacing.md
|
2018-05-03 00:27:19 +02:00
|
|
|
//
|
|
|
|
// Disabled for now - if anything we'd like to *enforce* spacing in JSX
|
|
|
|
// curly brackets for legibility, but in practice it's not clear that the
|
|
|
|
// consistency particularly improves legibility here. --Matthew
|
|
|
|
//
|
|
|
|
// "react/jsx-curly-spacing": ["error", {"when": "never", "children": {"when": "always"}}],
|
2017-09-28 11:02:40 +02:00
|
|
|
|
2017-09-28 11:27:03 +02:00
|
|
|
// Assert spacing before self-closing JSX tags, and no spacing before or
|
|
|
|
// after the closing slash, and no spacing after the opening bracket of
|
|
|
|
// the opening tag or closing tag.
|
|
|
|
//
|
|
|
|
// https://github.com/yannickcr/eslint-plugin-react/blob/HEAD/docs/rules/jsx-tag-spacing.md
|
|
|
|
"react/jsx-tag-spacing": ["error"],
|
|
|
|
|
2017-01-20 15:08:14 +01:00
|
|
|
/** flowtype **/
|
|
|
|
"flowtype/require-parameter-type": ["warn", {
|
|
|
|
"excludeArrowFunctions": true,
|
|
|
|
}],
|
|
|
|
"flowtype/define-flow-type": "warn",
|
|
|
|
"flowtype/require-return-type": ["warn",
|
|
|
|
"always",
|
|
|
|
{
|
|
|
|
"annotateUndefined": "never",
|
|
|
|
"excludeArrowFunctions": true,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"flowtype/space-after-type-colon": ["warn", "always"],
|
|
|
|
"flowtype/space-before-type-colon": ["warn", "never"],
|
|
|
|
|
|
|
|
/*
|
|
|
|
* things that are errors in the js-sdk config that the current
|
|
|
|
* code does not adhere to, turned down to warn
|
|
|
|
*/
|
2017-02-01 10:59:46 +01:00
|
|
|
"max-len": ["warn", {
|
|
|
|
// apparently people believe the length limit shouldn't apply
|
|
|
|
// to JSX.
|
|
|
|
ignorePattern: '^\\s*<',
|
2017-02-02 11:52:11 +01:00
|
|
|
ignoreComments: true,
|
2019-02-05 20:31:14 +01:00
|
|
|
ignoreRegExpLiterals: true,
|
2017-04-29 15:22:06 +02:00
|
|
|
code: 120,
|
2017-02-01 10:59:46 +01:00
|
|
|
}],
|
2017-01-20 15:08:14 +01:00
|
|
|
"valid-jsdoc": ["warn"],
|
|
|
|
"new-cap": ["warn"],
|
|
|
|
"key-spacing": ["warn"],
|
|
|
|
"prefer-const": ["warn"],
|
|
|
|
|
|
|
|
// crashes currently: https://github.com/eslint/eslint/issues/6274
|
|
|
|
"generator-star-spacing": "off",
|
|
|
|
},
|
|
|
|
settings: {
|
|
|
|
flowtype: {
|
|
|
|
onlyFilesWithFlowAnnotation: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|