Skip to content

Commit

Permalink
Add no default exports custom rule (#10981)
Browse files Browse the repository at this point in the history
* Introduce a custom kibana estlint rule for no default exports

Turn it on only at the level of /kibana/src/core_plugins/public/ for
now, just to keep the PR sizes manageable.

* Don't call functions directly on the import

* Create a packages dir and move the custom rule in there

* Remove copied package.json portions, use minimal info necessary
  • Loading branch information
stacey-gammon authored Apr 12, 2017
1 parent 49255e0 commit 5aea4ff
Show file tree
Hide file tree
Showing 32 changed files with 58 additions and 44 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
"eslint": "3.11.1",
"eslint-plugin-babel": "4.0.0",
"eslint-plugin-jest": "19.0.1",
"eslint-plugin-kibana-custom": "file:packages/custom-eslint-rules",
"eslint-plugin-mocha": "4.7.0",
"eslint-plugin-react": "6.10.3",
"event-stream": "3.3.2",
Expand Down
7 changes: 7 additions & 0 deletions packages/custom-eslint-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports.rules = {
'no-default-export': context => ({
ExportDefaultDeclaration: (node) => {
context.report(node, 'Default exports not allowed.');
}
})
};
5 changes: 5 additions & 0 deletions packages/custom-eslint-rules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "eslint-plugin-kibana-custom",
"version": "1.0.0",
"description": "Custom ESLint rules for Kibana"
}
5 changes: 5 additions & 0 deletions src/core_plugins/kibana/public/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@

plugins: [
'kibana-custom'
]
rules:
no-console: 2
kibana-custom/no-default-export: error
3 changes: 2 additions & 1 deletion src/core_plugins/kibana/public/dashboard/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'plugins/kibana/dashboard/panel/get_object_loaders_for_dashboard';
import FilterManagerProvider from 'ui/filter_manager';
import uiModules from 'ui/modules';
import panelTemplate from 'plugins/kibana/dashboard/panel/panel.html';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';
import { getPersistedStateId } from 'plugins/kibana/dashboard/panel/panel_state';
import { loadSavedObject } from 'plugins/kibana/dashboard/panel/load_saved_object';
import { DashboardViewMode } from '../dashboard_view_mode';
Expand All @@ -15,7 +16,7 @@ uiModules
.directive('dashboardPanel', function (savedVisualizations, savedSearches, Notifier, Private, $injector, getObjectLoadersForDashboard) {
const filterManager = Private(FilterManagerProvider);

const services = require('plugins/kibana/management/saved_object_registry').all().map(function (serviceObj) {
const services = savedObjectManagementRegistry.all().map(function (serviceObj) {
const service = $injector.get(serviceObj.service);
return {
type: service.type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import 'plugins/kibana/dashboard/saved_dashboard/saved_dashboard';
import uiModules from 'ui/modules';
import { SavedObjectLoader } from 'ui/courier/saved_object/saved_object_loader';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';

const module = uiModules.get('app/dashboard');

// bring in the factory


// Register this service with the saved object registry so it can be
// edited by the object editor.
require('plugins/kibana/management/saved_object_registry').register({
savedObjectManagementRegistry.register({
service: 'savedDashboards',
title: 'dashboards'
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import _ from 'lodash';
import ngMock from 'ng_mock';
import fieldCalculator from 'plugins/kibana/discover/components/field_chooser/lib/field_calculator';
import { fieldCalculator } from 'plugins/kibana/discover/components/field_chooser/lib/field_calculator';
import expect from 'expect.js';
import 'ui/private';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'angular-ui-select';
import _ from 'lodash';
import $ from 'jquery';
import rison from 'rison-node';
import fieldCalculator from 'plugins/kibana/discover/components/field_chooser/lib/field_calculator';
import { fieldCalculator } from 'plugins/kibana/discover/components/field_chooser/lib/field_calculator';
import IndexPatternsFieldListProvider from 'ui/index_patterns/_field_list';
import uiModules from 'ui/modules';
import fieldChooserTemplate from 'plugins/kibana/discover/components/field_chooser/field_chooser.html';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function _groupValues(allValues, params) {
return groups;
}

export default {
export const fieldCalculator = {
_groupValues: _groupValues,
_countMissing: _countMissing,
getFieldValues: getFieldValues,
Expand Down
2 changes: 1 addition & 1 deletion src/core_plugins/kibana/public/discover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import 'plugins/kibana/discover/controllers/discover';
import 'plugins/kibana/discover/styles/main.less';
import 'ui/doc_table/components/table_row';
import savedObjectRegistry from 'ui/saved_objects/saved_object_registry';
import savedSearchProvider from 'plugins/kibana/discover/saved_searches/saved_search_register';
import { savedSearchProvider } from 'plugins/kibana/discover/saved_searches/saved_search_register';

savedObjectRegistry.register(savedSearchProvider);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function savedSearchObjectFn(savedSearches) {
export function savedSearchProvider(savedSearches) {
return savedSearches;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import 'plugins/kibana/discover/saved_searches/_saved_search';
import 'ui/notify';
import uiModules from 'ui/modules';
import { SavedObjectLoader } from 'ui/courier/saved_object/saved_object_loader';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';
const module = uiModules.get('discover/saved_searches', [
'kibana/notify'
]);

// Register this service with the saved object registry so it can be
// edited by the object editor.
require('plugins/kibana/management/saved_object_registry').register({
savedObjectManagementRegistry.register({
service: 'savedSearches',
title: 'searches'
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';
const registry = [];
export default {
export const savedObjectManagementRegistry = {
register: function (service) {
registry.push(service);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import { IndexPatternMissingIndices } from 'ui/errors';
import 'ui/directives/validate_index_name';
import 'ui/directives/auto_select_if_only_one';
import RefreshKibanaIndex from 'plugins/kibana/management/sections/indices/_refresh_kibana_index';
import { RefreshKibanaIndex } from 'plugins/kibana/management/sections/indices/_refresh_kibana_index';
import uiRoutes from 'ui/routes';
import uiModules from 'ui/modules';
import createTemplate from 'plugins/kibana/management/sections/indices/_create.html';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';

export default function (indexPattern) {
export function dateScripts(indexPattern) {
const dateScripts = {};
const scripts = {
__dayOfMonth: 'dayOfMonth',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'plugins/kibana/management/sections/indices/_indexed_fields';
import 'plugins/kibana/management/sections/indices/_scripted_fields';
import 'plugins/kibana/management/sections/indices/source_filters/source_filters';
import 'plugins/kibana/management/sections/indices/_index_header';
import RefreshKibanaIndex from 'plugins/kibana/management/sections/indices/_refresh_kibana_index';
import { RefreshKibanaIndex } from 'plugins/kibana/management/sections/indices/_refresh_kibana_index';
import UrlProvider from 'ui/url';
import IndicesEditSectionsProvider from 'plugins/kibana/management/sections/indices/_edit_sections';
import { IndicesEditSectionsProvider } from 'plugins/kibana/management/sections/indices/_edit_sections';
import uiRoutes from 'ui/routes';
import uiModules from 'ui/modules';
import editTemplate from 'plugins/kibana/management/sections/indices/_edit.html';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash';
export default function GetFieldTypes() {

export function IndicesEditSectionsProvider() {

return function (indexPattern) {
const fieldCount = _.countBy(indexPattern.fields, function (field) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function RefreshKibanaIndexFn(esAdmin, kbnIndex) {
export function RefreshKibanaIndex(esAdmin, kbnIndex) {
return function () {
return esAdmin.indices.refresh({
index: kbnIndex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import 'ui/paginated_table';
import controlsHtml from 'plugins/kibana/management/sections/indices/_field_controls.html';
import dateScripts from 'plugins/kibana/management/sections/indices/_date_scripts';
import { dateScripts } from 'plugins/kibana/management/sections/indices/_date_scripts';
import uiModules from 'ui/modules';
import scriptedFieldsTemplate from 'plugins/kibana/management/sections/indices/_scripted_fields.html';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { saveAs } from '@spalger/filesaver';
import { extend, find, flattenDeep, partialRight, pick, pluck, sortBy } from 'lodash';
import angular from 'angular';
import registry from 'plugins/kibana/management/saved_object_registry';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';
import objectIndexHTML from 'plugins/kibana/management/sections/objects/_objects.html';
import 'ui/directives/file_upload';
import uiRoutes from 'ui/routes';
Expand Down Expand Up @@ -38,7 +38,7 @@ uiModules.get('apps/management')
};

const getData = function (filter) {
const services = registry.all().map(function (obj) {
const services = savedObjectManagementRegistry.all().map(function (obj) {
const service = $injector.get(obj.service);
return service.find(filter).then(function (data) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import angular from 'angular';
import rison from 'rison-node';
import registry from 'plugins/kibana/management/saved_object_registry';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';
import objectViewHTML from 'plugins/kibana/management/sections/objects/_view.html';
import IndexPatternsCastMappingTypeProvider from 'ui/index_patterns/_cast_mapping_type';
import uiRoutes from 'ui/routes';
Expand All @@ -19,7 +19,7 @@ uiModules.get('apps/management')
controller: function ($scope, $injector, $routeParams, $location, $window, $rootScope, esAdmin, Private) {
const notify = new Notifier({ location: 'SavedObject view' });
const castMappingType = Private(IndexPatternsCastMappingTypeProvider);
const serviceObj = registry.get($routeParams.service);
const serviceObj = savedObjectManagementRegistry.get($routeParams.service);
const service = $injector.get(serviceObj.service);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import toEditableConfig from 'plugins/kibana/management/sections/settings/lib/to_editable_config';
import { toEditableConfig } from 'plugins/kibana/management/sections/settings/lib/to_editable_config';
import 'plugins/kibana/management/sections/settings/advanced_row';
import management from 'ui/management';
import uiRoutes from 'ui/routes';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import getEditorType from 'plugins/kibana/management/sections/settings/lib/get_editor_type';
import { getEditorType } from 'plugins/kibana/management/sections/settings/lib/get_editor_type';
import expect from 'expect.js';

describe('Settings', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import getValType from 'plugins/kibana/management/sections/settings/lib/get_val_type';
import { getValType } from 'plugins/kibana/management/sections/settings/lib/get_val_type';
import expect from 'expect.js';

describe('Settings', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import toEditableConfig from 'plugins/kibana/management/sections/settings/lib/to_editable_config';
import { toEditableConfig } from 'plugins/kibana/management/sections/settings/lib/to_editable_config';
import expect from 'expect.js';

describe('Settings', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const NORMAL_EDITOR = ['number', 'string', 'null', 'undefined'];
* @param {object} advanced setting configuration object
* @returns {string} the editor type to use when editing value
*/
function getEditorType(conf) {
export function getEditorType(conf) {
if (_.contains(NAMED_EDITORS, conf.type)) return conf.type;
if (_.contains(NORMAL_EDITOR, conf.type)) return 'normal';
}

export default getEditorType;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';
* @param {?} current value of the setting
* @returns {string} the type to use for determining the display and editor
*/
function getValType(def, value) {
export function getValType(def, value) {
if (def.type) {
return def.type;
}
Expand All @@ -16,5 +16,3 @@ function getValType(def, value) {

return (def.value != null ? typeof def.value : typeof value);
}

export default getValType;
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import getValType from './get_val_type';
import getEditorType from './get_editor_type';
import { getValType } from './get_val_type';
import { getEditorType } from './get_editor_type';

/**
* @param {object} advanced setting definition object
* @param {object} name of setting
* @param {object} current value of setting
* @returns {object} the editable config object
*/
function toEditableConfig({ def, name, value, isCustom }) {
export function toEditableConfig({ def, name, value, isCustom }) {
if (!def) {
def = {};
}
Expand All @@ -33,5 +33,3 @@ function toEditableConfig({ def, name, value, isCustom }) {

return conf;
}

export default toEditableConfig;
4 changes: 2 additions & 2 deletions src/core_plugins/kibana/public/visualize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import visualizeListingTemplate from './listing/visualize_listing.html';
import { VisualizeListingController } from './listing/visualize_listing';
import { VisualizeConstants } from './visualize_constants';
import savedObjectRegistry from 'ui/saved_objects/saved_object_registry';
import savedVisusalizationProvider from 'plugins/kibana/visualize/saved_visualizations/saved_visualization_register';
import { savedVisualizationProvider } from 'plugins/kibana/visualize/saved_visualizations/saved_visualization_register';

uiRoutes
.defaults(/visualize/, {
Expand All @@ -35,4 +35,4 @@ uiRoutes

// preloading

savedObjectRegistry.register(savedVisusalizationProvider);
savedObjectRegistry.register(savedVisualizationProvider);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function savedVisualizationFn(savedVisualizations) {
export function savedVisualizationProvider(savedVisualizations) {
return savedVisualizations;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'plugins/kibana/visualize/saved_visualizations/_saved_vis';
import RegistryVisTypesProvider from 'ui/registry/vis_types';
import uiModules from 'ui/modules';
import { SavedObjectLoader } from 'ui/courier/saved_object/saved_object_loader';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';

const app = uiModules.get('app/visualize');


// Register this service with the saved object registry so it can be
// edited by the object editor.
require('plugins/kibana/management/saved_object_registry').register({
savedObjectManagementRegistry.register({
service: 'savedVisualizations',
title: 'visualizations'
});
Expand Down
3 changes: 2 additions & 1 deletion src/core_plugins/timelion/public/services/saved_sheets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SavedObjectLoader } from 'ui/courier/saved_object/saved_object_loader';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';

define(function (require) {
const module = require('ui/modules').get('app/sheet');
Expand All @@ -8,7 +9,7 @@ define(function (require) {

// Register this service with the saved object registry so it can be
// edited by the object editor.
require('plugins/kibana/management/saved_object_registry').register({
savedObjectManagementRegistry.register({
service: 'savedSheets',
title: 'sheets'
});
Expand Down

0 comments on commit 5aea4ff

Please sign in to comment.