I eslint + babel-eslint + eslint-plugin-react + eslint-plugin-flowtype
eslint-plugin-flowtype nicht überprüft
zu konfigurieren versuche ich die folgende devDependencies
haben in package.json
:
"babel-eslint": "^7.1.1",
"eslint": "^3.10.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.7.1"
Und die folgende .eslinrc
:
{
"parser": "babel-eslint",
"plugins": [
"flowtype"
],
"extends": [
"airbnb",
"plugin:flowtype/recommended"
],
"rules": {
"max-len": [1, 80, 2, {"ignoreComments": true}],
"prop-types": [0],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/prefer-stateless-function": [
0,
{
"ignorePureComponents": true
}
],
"no-console": 0
},
"settings": {
"flowtype": {
"onlyFilesWithFlowAnnotation": true
}
}
}
Ich schrieb einfaches Codebeispiel in App.js
:
function foo() {
const a: string = 1;
return a;
}
async function bar() {
const b = await foo();
return b;
}
Wenn ich eslint src/App.js
starte, dann zeigt eslint
keine Nachrichten an. Wenn ich hinzufügen "flowtype/require-return-type": 2
in .eslintrc
dann eslint
zeigt:
error Missing return type annotation flowtype/require-return-type
error Missing return type annotation flowtype/require-return-type
✖ 2 problems (2 errors, 0 warnings)
Aber ich verstehe nicht, warum const a: string = 1;
gültig ist. Wie kann der Prüftyp const a: string = 1;
aktiviert werden?
Vielen Dank für die Antwort! Weißt du, ist es möglich, 'flowtype + eslint' zu verwenden? Ich meine, ist es möglich, 'eslint' Fehler von' flowtype' zu zeigen, wenn ich 'eslint App.js' starte? –
Es ist möglich, aber niemand, dem ich bewusst bin, hat etwas geschrieben, um den Flow in ESLint anzuzeigen. Persönlich denke ich nicht, dass es eine gute Idee wäre. Es ist besser, Flow wie vorgesehen zu verwenden und ESLint wie vorgesehen als separate Tools zu verwenden. –