Revert "[packages] prevent and remove basename collisions for js/ts code"

This reverts commit bba406b9b0.
This commit is contained in:
spalger 2023-01-12 10:49:59 -07:00
parent 6bdc5bfd54
commit 8e12174d32
No known key found for this signature in database
5 changed files with 18 additions and 47 deletions

View file

@ -9,6 +9,5 @@
import type { PackageRule } from '@kbn/repo-linter';
import { matchingPackageNameRule } from './matching_package_name';
import { noBasenameCollisionsRule } from './no_basename_collisions';
export const RULES: PackageRule[] = [matchingPackageNameRule, noBasenameCollisionsRule];
export const RULES: PackageRule[] = [matchingPackageNameRule];

View file

@ -1,40 +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 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<string, string>();
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}`
);
}
}
},
});

View file

@ -36,7 +36,7 @@ export class RepoPath {
private _basename: string | undefined;
/**
* basename of the path (including extension)
* basename of the path
* (lazy and cached getter)
*/
public get basename() {
@ -64,10 +64,6 @@ 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')) {

View file

@ -0,0 +1,8 @@
/*
* 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';

View file

@ -0,0 +1,8 @@
/*
* 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';