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

[eslint] enable no undef #10825

Merged
merged 23 commits into from
Mar 22, 2017
Merged

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Mar 21, 2017

Re-enabled the no-undef eslint rule and fixed all the violation using a mixture of jscodeshift transforms and manual adjustments.

@spalger spalger force-pushed the eslint/enable-no-undef branch from ed1bceb to 2dd2761 Compare March 21, 2017 03:28
@spalger spalger requested a review from kimjoar March 21, 2017 09:59
@spalger spalger changed the title [WIP][Eslint] enable no undef [eslint] enable no undef Mar 21, 2017
@spalger spalger added the review label Mar 21, 2017
@@ -83,8 +80,8 @@ module.exports = class ClusterManager {
}

setupWatching(extraPaths) {
const chokidar = require('chokidar');
const fromRoot = require('../../utils/from_root');
const chokidar = require('chokidar'); // kibana-jscodeshift-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

// kibana-jscodeshift-ignore

What is this?

Copy link
Contributor Author

@spalger spalger Mar 21, 2017

Choose a reason for hiding this comment

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

It's a signal to the jscodeshift transforms that the require statement on that line needs to stay on that line, I planned to remove them before submitting the pr


function fixture(name) {
return resolve(__dirname, 'fixtures', name);
}

describe('cli/serve/read_yaml_config', function () {
it('reads a single config file', function () {
const config = readYamlConfig(fixture('one.yml'));
readYamlConfig(fixture('one.yml'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this call anymore? Are there other places where we have situations like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't look like it

@@ -33,7 +33,7 @@ describe(`Server logging configuration`, function () {

let asserted = false;
let json = Infinity;
const conf = setLoggingJson(true);
setLoggingJson(true);
Copy link
Contributor

@w33ble w33ble Mar 21, 2017

Choose a reason for hiding this comment

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

Do we need this call anymore? What is this doing?

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, this is writing a config file that is then read by the server on startup.

@@ -83,8 +80,8 @@ module.exports = class ClusterManager {
}

setupWatching(extraPaths) {
const chokidar = require('chokidar');
const fromRoot = require('../../utils/from_root');
const chokidar = require('chokidar'); // kibana-jscodeshift-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

What's kibana-jscodeshift-ignore?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ignore require -> import?

@@ -17,7 +17,7 @@ async function listPackages(settings) {
.map(file => file.replace(/\\/g, '/'))
.map(file => file.match(regExp))
.compact()
.map(([ file, _, folder ]) => ({ file, folder }))
Copy link
Contributor

Choose a reason for hiding this comment

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

^^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another thing that eslint complains about. If we really don't like this style I think we should just stop destructuring the arg.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, true. I'll live with it. It's just JS being weird.

@@ -37,13 +37,13 @@ function UrlParams(description, defaults) {
description = _.clone(description || {});
_.defaults(description, defaults);
_.each(description, function (p_description, param) {
var values, component;
var component;
component = new ParamComponent(param, this.rootComponent, p_description);
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: could be changed to const component = new ParamComponent(...) now

@@ -10,7 +9,7 @@ var HighlightRules = require("./output_highlight_rules").OutputJsonHighlightRule
var MatchingBraceOutdent = ace.require("ace/mode/matching_brace_outdent").MatchingBraceOutdent;
var CstyleBehaviour = ace.require("ace/mode/behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = ace.require("ace/mode/folding/cstyle").FoldMode;
var WorkerClient = ace.require("ace/worker/worker_client").WorkerClient;
Copy link
Contributor

Choose a reason for hiding this comment

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

This require has side-effects?

Copy link
Contributor Author

@spalger spalger Mar 21, 2017

Choose a reason for hiding this comment

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

I'm not sure, playing it safe

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -2,10 +2,8 @@ require('ace');

const module = require('ui/modules').get('app/sense');

module.run(function (Private, $rootScope) {
module.setupResizeCheckerForRootEditors = ($el, ...editors) => {
// mock the resize checker
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe keep the comment? (can put it above instead of within)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

const { series, markings } = newProps;
const {
series
} = newProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: styling

@@ -68,7 +68,7 @@ class Timeseries extends Component {
if (row.data[i] && pos.x < row.data[i][0]) break;
}
if (!row.data[closest]) return values[row.id] = null;
const [ time, value ] = row.data[closest];
const [ , value ] = row.data[closest];
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, I think this is actually legal, but for clarity we probably want to keep time here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eslint complains, and I think that's the right thing to do unless we want to pick a variable pattern we can use for unused placeholders (something we can tell eslint to ignore, like unused{N})

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it should just be const value = row.data[closest][1]? I just found this a bit "confusing" (as in: I wasn't sure whether or not it was actually legal, which I find to be a bad sign)

(However: I'm absolutely okey with keeping it, I think enabling this rule in eslint is much more important than discussing this case)

@@ -23,7 +22,6 @@ module.exports = function (directory) {
})
.map(function (file) {
const parts = file.split('/');
const name = parts[parts.length - 2];
return getTuple(directory, parts[parts.length - 2]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe getTuple(directory, name) instead of removing name?

@@ -25,14 +22,12 @@ const init = function () {
// Load the application
ngMock.module('kibana');

ngMock.module('kibana', function ($provide) {
ngMock.module('kibana', function () {
});
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed anymore?

@@ -44,8 +44,7 @@ export default class DashboardPage {
await PageObjects.common.try(async () => {
const goToDashboardLink = await PageObjects.common.findByCssSelector('a[href="#/dashboard"]');
await goToDashboardLink.click();
// Once the searchFilter can be found, we know the page finished loading.
const searchFilter = await PageObjects.common.findTestSubject('searchFilter');
Copy link
Contributor

Choose a reason for hiding this comment

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

keep the comment?

@spalger
Copy link
Contributor Author

spalger commented Mar 22, 2017

@w33ble @kjbekkelund pushed updates to address feedback if you would like to take another look

} = props;

const aggs = model.metrics.map(createAggRowRender(props));

let caretClassName = 'fa fa-caret-down';
if (!visible) caretClassName = 'fa fa-caret-right';
!visible;
Copy link
Contributor

Choose a reason for hiding this comment

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

Now commenting on the correct line 🙈 This one is weird ^

@@ -64,7 +64,8 @@ uiModules.get('apps/management')
});

$scope.$watchCollection('indexPattern.fields', function () {
$scope.indexPattern.fields.filter(() => { type: 'conflict'; });
$scope.conflictFields = $scope.indexPattern.fields
.filter(field => field.type === 'conflict');
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks @spalger!

Copy link
Contributor

@kimjoar kimjoar left a comment

Choose a reason for hiding this comment

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

As far as I can see this looks great now.

@spalger spalger merged commit d8d6552 into elastic:master Mar 22, 2017
@epixa
Copy link
Contributor

epixa commented Mar 22, 2017

Can we do this change to 5.x as well? @jgowdyelastic Would this be a problem for ML? I think this is already happening on x-pack-kibana, but I figured I'd confirm anyway.

@stacey-gammon
Copy link
Contributor

stacey-gammon commented Mar 22, 2017

Hm, I'm not sure how this passed, I am getting build failures on a PR for code I didn't touch:
https://kibana-ci.elastic.co/job/elastic+kibana+pull-request+multijob-intake/4866/console

screen shot 2017-03-22 at 11 15 01 am

e.g. this file still seems to have issues:
https://github.com/elastic/kibana/blob/master/src/core_plugins/metrics/public/lib/__tests__/add_scope.js

@spalger the rule doesn't seem to pick up when a component is used in inlined html. e.g.:

  it('adds $scope variables as props to wrapped component', () => {
    const WrappedComponent = addScope(Component, $scope, ['testOne', 'testTwo']);
    const wrapper = shallow(<WrappedComponent/>);
    expect(wrapper.state('testOne')).to.equal(1);
    expect(wrapper.state('testTwo')).to.equal(2);
  });

the WrappedComponent is throwing the error, but I think it's still needed because it's used in the < tags /> Did you encounter this?

spalger added a commit that referenced this pull request Mar 22, 2017
* [codeshift] add proper ignore comments

* use more descriptive file ignore pattern

* [codeshift] apply require-to-import transform

* [codeshift/fixup] remove duplicate imports

* [eslint] upgrade config for react "unused" support

(cherry picked from commit aa2bb17)

* [eslint] remove no-unused-vars override

* [eslint] remove no-unused-vars override

* add eslint-plugin-react peerDependency

* [codeshift] apply remove-unused-basic-requires transform

* [codeshift] apply remove-unused-function-arguments transform

* [lintroller] fix argument list spacing

* [codeshift] apply remove-unused-basic-vars transform

* [codeshift/fixup] fixup unused basic var removals

* manually apply remove-unused-assignments transform

* [codeshift] reapply remove-unused-imports transform

* [codeshift] reapply remove-unused-function-arguments transform

* [resizeChecker] remove assignment to unused var

* [eslint] autofix param spacing

* manually fix remaining no-undef errors

* replace values that looked unused in tests

* remove // kibana-jscodeshift-no-babel comment

* remove import statements from code required by api tests

* Remove '// kibana-jscodeshift-ignore' comments

* address review feedback

* remove remnant of removed if condition

* [console] use * import for settings
@spalger spalger deleted the eslint/enable-no-undef branch March 29, 2017 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants