Skip to content

[New] version: detect-no-warn #2718

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

Closed
wants to merge 2 commits into from
Closed
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: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ You should also specify settings that will be shared across all the plugin rules
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// default to latest and warns if missing
// It will default to "detect" in the future
// You can also set it to `"detect-no-warn"`, which is the same as "detect", but does not give a warning
"flowVersion": "0.53" // Flow version
},
"propWrapperFunctions": [
Expand Down
11 changes: 9 additions & 2 deletions lib/util/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const error = require('./error');

let warnedForMissingVersion = false;

let detectNoWarn = false;

function resetWarningFlag() {
warnedForMissingVersion = false;
}
Expand All @@ -33,8 +35,10 @@ function detectReactVersion() {
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
if (!warnedForMissingVersion) {
error('Warning: React version was set to "detect" in eslint-plugin-react settings, '
+ 'but the "react" package is not installed. Assuming latest React version for linting.');
if (!detectNoWarn) {
error('Warning: React version was set to "detect" in eslint-plugin-react settings, '
+ 'but the "react" package is not installed. Assuming latest React version for linting.');
}
warnedForMissingVersion = true;
}
cachedDetectedReactVersion = '999.999.999';
Expand All @@ -51,6 +55,9 @@ function getReactVersionFromContext(context) {
let settingsVersion = context.settings.react.version;
if (settingsVersion === 'detect') {
settingsVersion = detectReactVersion();
} else if (settingsVersion === 'detect-no-warn') {
settingsVersion = detectReactVersion();
detectNoWarn = true;
}
if (typeof settingsVersion !== 'string') {
error('Warning: React version specified in eslint-plugin-react-settings must be a string; '
Expand Down