Skip to content

chore(lint): turn on curly again #10931

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,12 @@ export default tseslint.config(
rules: { 'tsdoc/syntax': 0 },
},
prettierRuleset,
{
files: [`**/*${commonFiles}`],
rules: {
// Re-enable curly brace rule
curly: 2,
},
},
// oxlintRuleset,
);
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ export function ApiItemContainerMixin<TBaseClass extends IApiItemConstructor>(
default:
for (const child of node.getChildNodes()) {
const result = findPlainTextNode(child);
if (result) return result;
if (result) {
return result;
}
}
}

Expand Down Expand Up @@ -540,13 +542,14 @@ export function ApiItemContainerMixin<TBaseClass extends IApiItemConstructor>(
) {
for (const [index, key] of (apiItem as ApiClass | ApiInterface).typeParameters.entries() ?? []) {
const typeParameter = extendsType.typeParameters?.[index];
if (typeParameter)
if (typeParameter) {
mappedTypeParameters.set(key.name, { item: next.item as ApiDeclaredItem, range: typeParameter });
else if (key.defaultTypeExcerpt)
} else if (key.defaultTypeExcerpt) {
mappedTypeParameters.set(key.name, {
item: apiItem as ApiDeclaredItem,
range: key.defaultTypeExcerpt.tokenRange,
});
}
}
}

Expand Down
21 changes: 14 additions & 7 deletions packages/api-extractor-model/src/model/ApiPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented
public static loadFromJson(rawJson: any, apiJsonFilename: string = ''): ApiPackage {
const jsonObject =
MinifyJSONMapping.metadata in rawJson ? this._mapFromMinified(rawJson) : (rawJson as IApiPackageJson);
if (!jsonObject?.metadata) throw new Error(util.inspect(rawJson, { depth: 2 }));
if (!jsonObject?.metadata) {
throw new Error(util.inspect(rawJson, { depth: 2 }));
}

if (!jsonObject?.metadata || typeof jsonObject.metadata.schemaVersion !== 'number') {
throw new Error(
`Error loading ${apiJsonFilename}:` +
Expand Down Expand Up @@ -419,17 +422,19 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented

private _mapToMinified(jsonObject: IApiPackageJson) {
const mapper = (item: any): any => {
if (Array.isArray(item)) return item.map(mapper);
else {
if (Array.isArray(item)) {
return item.map(mapper);
} else {
const result: any = {};
for (const key of Object.keys(item)) {
if (key === 'dependencies') {
result[MinifyJSONMapping.dependencies] = item.dependencies;
} else if (key === 'tsdocConfig') {
result[MinifyJSONMapping.tsdocConfig] = item.tsdocConfig;
} else
} else {
result[MinifyJSONMapping[key as keyof typeof MinifyJSONMapping]] =
typeof item[key] === 'object' ? mapper(item[key]) : item[key];
}
}

return result;
Expand All @@ -441,20 +446,22 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented

private static _mapFromMinified(jsonObject: any): IApiPackageJson {
const mapper = (item: any): any => {
if (Array.isArray(item)) return item.map(mapper);
else {
if (Array.isArray(item)) {
return item.map(mapper);
} else {
const result: any = {};
for (const key of Object.keys(item)) {
if (key === MinifyJSONMapping.dependencies) {
result.dependencies = item[MinifyJSONMapping.dependencies];
} else if (key === MinifyJSONMapping.tsdocConfig) {
result.tsdocConfig = item[MinifyJSONMapping.tsdocConfig];
} else
} else {
result[
Object.keys(MinifyJSONMapping).find(
(look) => MinifyJSONMapping[look as keyof typeof MinifyJSONMapping] === key,
)!
] = typeof item[key] === 'object' ? mapper(item[key]) : item[key];
}
}

return result;
Expand Down
9 changes: 6 additions & 3 deletions packages/api-extractor-model/src/model/Deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,22 +489,25 @@ export class Deserializer {
},
];

if (_class.extends)
if (_class.extends) {
excerptTokens.push({
kind: ExcerptTokenKind.Reference,
text: formatVarType(_class.extends) ?? '',
canonicalReference: `${_package}!${getFirstType(_class.extends) ?? ''}:class`,
});
}

if (_class.extends && _class.implements)
if (_class.extends && _class.implements) {
excerptTokens.push({ kind: ExcerptTokenKind.Content, text: ' implements ' });
}

if (_class.implements)
if (_class.implements) {
excerptTokens.push({
kind: ExcerptTokenKind.Reference,
text: formatVarType(_class.implements) ?? '',
canonicalReference: `${_package}!${getFirstType(_class.implements) ?? ''}:class`,
});
}

members.push({
members: classMembers,
Expand Down
9 changes: 7 additions & 2 deletions packages/api-extractor/src/collector/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ export class Collector {
* The star is used as a delimiter because it is not a legal identifier character.
*/
public static getSortKeyIgnoringUnderscore(identifier: string | undefined): string {
if (!identifier) return '';
if (!identifier) {
return '';
}

let parts: string[];

Expand Down Expand Up @@ -532,7 +534,10 @@ export class Collector {
entryPoint: IWorkingPackageEntryPoint,
alreadySeenAstEntities: Set<AstEntity>,
): void {
if (alreadySeenAstEntities.has(astEntity)) return;
if (alreadySeenAstEntities.has(astEntity)) {
return;
}

alreadySeenAstEntities.add(astEntity);

if (astEntity instanceof AstSymbol) {
Expand Down
8 changes: 6 additions & 2 deletions packages/api-extractor/src/collector/CollectorEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export class CollectorEntity {
*/
public get exported(): boolean {
// Exported from top-level?
if (this.exportedFromEntryPoint) return true;
if (this.exportedFromEntryPoint) {
return true;
}

// Exported from parent?
for (const localExportNames of this._localExportNamesByParent.values()) {
Expand Down Expand Up @@ -162,7 +164,9 @@ export class CollectorEntity {
*/
public get consumable(): boolean {
// Exported from top-level?
if (this.exportedFromEntryPoint) return true;
if (this.exportedFromEntryPoint) {
return true;
}

// Exported from consumable parent?
for (const [parent, localExportNames] of this._localExportNamesByParent) {
Expand Down
12 changes: 9 additions & 3 deletions packages/api-extractor/src/collector/SourceMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ export class SourceMapper {
}

const sourceMap: ISourceMap | null = this._getSourceMap(sourceFilePath);
if (!sourceMap) return;
if (!sourceMap) {
return;
}

const nearestMappingItem: MappingItem | undefined = SourceMapper._findNearestMappingItem(sourceMap.mappingItems, {
line: sourceFileLine,
column: sourceFileColumn,
});

if (!nearestMappingItem) return;
if (!nearestMappingItem) {
return;
}

const mappedFilePath: string = path.resolve(path.dirname(sourceFilePath), nearestMappingItem.source);

Expand All @@ -132,7 +136,9 @@ export class SourceMapper {
}

// Don't translate coordinates to a file that doesn't exist
if (!originalFileInfo.fileExists) return;
if (!originalFileInfo.fileExists) {
return;
}

// The nearestMappingItem anchor may be above/left of the real position, due to gaps in the mapping. Calculate
// the delta and apply it to the original position.
Expand Down
5 changes: 4 additions & 1 deletion packages/builders/src/util/normalizeArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* @param arr - The (possibly variadic) data to normalize
*/
export function normalizeArray<ItemType>(arr: RestOrArray<ItemType>): ItemType[] {
if (Array.isArray(arr[0])) return [...arr[0]];
if (Array.isArray(arr[0])) {
return [...arr[0]];
}

return arr as ItemType[];
}

Expand Down
4 changes: 3 additions & 1 deletion packages/collection/__tests__/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,9 @@ describe('random() tests', () => {
const chars = 'abcdefghijklmnopqrstuvwxyz';
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26];

for (let i = 0; i < chars.length; i++) coll.set(chars[i]!, numbers[i]!);
for (let i = 0; i < chars.length; i++) {
coll.set(chars[i]!, numbers[i]!);
}

const random = coll.random(5);
expect(random.length).toBe(5);
Expand Down
Loading