diff --git a/packages/kbn-lint-packages-cli/rules/index.ts b/packages/kbn-lint-packages-cli/rules/index.ts index a75d2fb50bee..65f16c71d74f 100644 --- a/packages/kbn-lint-packages-cli/rules/index.ts +++ b/packages/kbn-lint-packages-cli/rules/index.ts @@ -9,5 +9,6 @@ import type { PackageRule } from '@kbn/repo-linter'; import { matchingPackageNameRule } from './matching_package_name'; +import { noBasenameCollisionsRule } from './no_basename_collisions'; -export const RULES: PackageRule[] = [matchingPackageNameRule]; +export const RULES: PackageRule[] = [matchingPackageNameRule, noBasenameCollisionsRule]; diff --git a/packages/kbn-lint-packages-cli/rules/no_basename_collisions.ts b/packages/kbn-lint-packages-cli/rules/no_basename_collisions.ts new file mode 100644 index 000000000000..436514e9aeab --- /dev/null +++ b/packages/kbn-lint-packages-cli/rules/no_basename_collisions.ts @@ -0,0 +1,40 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import Path from 'path'; + +import { PackageRule } from '@kbn/repo-linter'; +import { SetMap } from '@kbn/set-map'; + +export const noBasenameCollisionsRule = PackageRule.create('noBasenameCollisions', { + async check() { + const groupedByBasename = new SetMap(); + + for (const file of this.getAllFiles()) { + if (!file.isJsTsCode()) { + continue; + } + + const repoRelWithoutExt = Path.resolve( + file.repoRelDir, + Path.basename(file.repoRel, file.ext) + ); + + groupedByBasename.add(repoRelWithoutExt, file.repoRel); + } + + for (const [, paths] of groupedByBasename) { + if (paths.size > 1) { + const list = Array.from(paths, (p) => `\n - ${p}`).join(''); + this.err( + `Having two JS/TS files with the same name but different extensions is not allowed:${list}` + ); + } + } + }, +}); diff --git a/packages/kbn-lint-packages-cli/tsconfig.json b/packages/kbn-lint-packages-cli/tsconfig.json index 30c6aaa3e32e..44df028e66ef 100644 --- a/packages/kbn-lint-packages-cli/tsconfig.json +++ b/packages/kbn-lint-packages-cli/tsconfig.json @@ -23,5 +23,6 @@ "@kbn/ts-projects", "@kbn/repo-file-maps", "@kbn/json-ast", + "@kbn/set-map", ] } diff --git a/packages/kbn-repo-path/repo_path.ts b/packages/kbn-repo-path/repo_path.ts index 86991b23a533..aad179917415 100644 --- a/packages/kbn-repo-path/repo_path.ts +++ b/packages/kbn-repo-path/repo_path.ts @@ -36,7 +36,7 @@ export class RepoPath { private _basename: string | undefined; /** - * basename of the path + * basename of the path (including extension) * (lazy and cached getter) */ public get basename() { @@ -64,6 +64,10 @@ export class RepoPath { return this.ext === '.js' || this.ext === '.jsx' || this.ext === '.mjs'; } + isJsTsCode() { + return this.isTypeScript() || this.isJavaScript(); + } + isFixture() { const parts = this.repoRel.split('/'); if (parts.includes('__fixtures__') || this.repoRel.endsWith('.test-d.ts')) { diff --git a/x-pack/plugins/ml/server/models/filter/index.js b/x-pack/plugins/ml/server/models/filter/index.js deleted file mode 100644 index 6f3657d9c027..000000000000 --- a/x-pack/plugins/ml/server/models/filter/index.js +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { FilterManager } from './filter_manager'; diff --git a/x-pack/plugins/watcher/common/lib/get_moment/index.js b/x-pack/plugins/watcher/common/lib/get_moment/index.js deleted file mode 100644 index 5c352d754d6e..000000000000 --- a/x-pack/plugins/watcher/common/lib/get_moment/index.js +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { getMoment } from './get_moment';