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

Enforce camelCase format for a plugin id #53759

Merged
merged 17 commits into from
Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## DiscoveredPlugin.configPath property

Root configuration path used by the plugin, defaults to "id".
Root configuration path used by the plugin, defaults to "id" in snake\_case format.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface DiscoveredPlugin

| Property | Type | Description |
| --- | --- | --- |
| [configPath](./kibana-plugin-server.discoveredplugin.configpath.md) | <code>ConfigPath</code> | Root configuration path used by the plugin, defaults to "id". |
| [configPath](./kibana-plugin-server.discoveredplugin.configpath.md) | <code>ConfigPath</code> | Root configuration path used by the plugin, defaults to "id" in snake\_case format. |
| [id](./kibana-plugin-server.discoveredplugin.id.md) | <code>PluginName</code> | Identifier of the plugin. |
| [optionalPlugins](./kibana-plugin-server.discoveredplugin.optionalplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that if installed and enabled \*\*may be\*\* leveraged by this plugin for some additional functionality but otherwise are not required for this plugin to work properly. |
| [requiredPlugins](./kibana-plugin-server.discoveredplugin.requiredplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that \*\*must be\*\* installed and enabled for this plugin to function properly. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## PluginManifest.configPath property

Root [configuration path](./kibana-plugin-server.configpath.md) used by the plugin, defaults to "id".
Root [configuration path](./kibana-plugin-server.configpath.md) used by the plugin, defaults to "id" in snake\_case format.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## PluginManifest.id property

Identifier of the plugin.
Identifier of the plugin. Must be a string in camelCase. Part of a plugin public contract. Other plugins leverage it to access plugin API, navigate to the plugin, etc.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Should never be used in code outside of Core but is exported for documentation p

| Property | Type | Description |
| --- | --- | --- |
| [configPath](./kibana-plugin-server.pluginmanifest.configpath.md) | <code>ConfigPath</code> | Root [configuration path](./kibana-plugin-server.configpath.md) used by the plugin, defaults to "id". |
| [id](./kibana-plugin-server.pluginmanifest.id.md) | <code>PluginName</code> | Identifier of the plugin. |
| [configPath](./kibana-plugin-server.pluginmanifest.configpath.md) | <code>ConfigPath</code> | Root [configuration path](./kibana-plugin-server.configpath.md) used by the plugin, defaults to "id" in snake\_case format. |
| [id](./kibana-plugin-server.pluginmanifest.id.md) | <code>PluginName</code> | Identifier of the plugin. Must be a string in camelCase. Part of a plugin public contract. Other plugins leverage it to access plugin API, navigate to the plugin, etc. |
| [kibanaVersion](./kibana-plugin-server.pluginmanifest.kibanaversion.md) | <code>string</code> | The version of Kibana the plugin is compatible with, defaults to "version". |
| [optionalPlugins](./kibana-plugin-server.pluginmanifest.optionalplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that if installed and enabled \*\*may be\*\* leveraged by this plugin for some additional functionality but otherwise are not required for this plugin to work properly. |
| [requiredPlugins](./kibana-plugin-server.pluginmanifest.requiredplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that \*\*must be\*\* installed and enabled for this plugin to function properly. |
Expand Down
1 change: 1 addition & 0 deletions src/core/CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ my_plugin/
   ├── index.ts
   └── plugin.ts
```
- [Manifest file](/docs/development/core/server/kibana-plugin-server.pluginmanifest.md) should be defined on top level.
- Both `server` and `public` should have an `index.ts` and a `plugin.ts` file:
- `index.ts` should only contain:
- The `plugin` export
Expand Down
25 changes: 14 additions & 11 deletions src/core/server/config/integration_tests/config_deprecation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ describe('configuration deprecations', () => {
await root.setup();

const logs = loggingServiceMock.collect(mockLoggingService);
expect(logs.warn).toMatchInlineSnapshot(`Array []`);
const warnings = logs.warn.flatMap(i => i);
expect(warnings).not.toContain(
'"optimize.lazy" is deprecated and has been replaced by "optimize.watch"'
);
expect(warnings).not.toContain(
'"optimize.lazyPort" is deprecated and has been replaced by "optimize.watchPort"'
);
});

it('should log deprecation warnings for core deprecations', async () => {
Expand All @@ -50,15 +56,12 @@ describe('configuration deprecations', () => {
await root.setup();

const logs = loggingServiceMock.collect(mockLoggingService);
expect(logs.warn).toMatchInlineSnapshot(`
Array [
Array [
"\\"optimize.lazy\\" is deprecated and has been replaced by \\"optimize.watch\\"",
],
Array [
"\\"optimize.lazyPort\\" is deprecated and has been replaced by \\"optimize.watchPort\\"",
],
]
`);
const warnings = logs.warn.flatMap(i => i);
expect(warnings).toContain(
'"optimize.lazy" is deprecated and has been replaced by "optimize.watch"'
);
expect(warnings).toContain(
'"optimize.lazyPort" is deprecated and has been replaced by "optimize.watchPort"'
);
});
});
42 changes: 42 additions & 0 deletions src/core/server/plugins/discovery/is_camel_case.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { isCamelCase } from './is_camel_case';

describe('isCamelCase', () => {
it('matches a string in camelCase', () => {
expect(isCamelCase('foo')).toBe(true);
expect(isCamelCase('foo1')).toBe(true);
expect(isCamelCase('fooBar')).toBe(true);
expect(isCamelCase('fooBarBaz')).toBe(true);
expect(isCamelCase('fooBAR')).toBe(true);
});

it('does not match strings in other cases', () => {
expect(isCamelCase('AAA')).toBe(false);
expect(isCamelCase('FooBar')).toBe(false);
expect(isCamelCase('3Foo')).toBe(false);
expect(isCamelCase('o_O')).toBe(false);
expect(isCamelCase('foo_bar')).toBe(false);
expect(isCamelCase('foo_')).toBe(false);
expect(isCamelCase('_fooBar')).toBe(false);
expect(isCamelCase('fooBar_')).toBe(false);
expect(isCamelCase('_fooBar_')).toBe(false);
});
});
22 changes: 22 additions & 0 deletions src/core/server/plugins/discovery/is_camel_case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const camelCaseRegExp = /^[a-z]{1}([a-zA-Z0-9]{1,})$/;
export function isCamelCase(candidate: string) {
return camelCaseRegExp.test(candidate);
}
Loading