Skip to content

Commit

Permalink
lint: enforce max line length / max items per line / one item per lin…
Browse files Browse the repository at this point in the history
…e for imports using import-newlines eslint plugin (#1730)
  • Loading branch information
filmaj authored Jan 19, 2024
1 parent d5c17d8 commit 99b939a
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 95 deletions.
12 changes: 10 additions & 2 deletions lint-configs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const jsDocRecommendedRulesOff = Object.assign(
...Object.keys(jsDocPlugin.configs.recommended.rules).map((rule) => ({ [rule]: 'off' })),
);

const MAX_LINE_LENGTH = 120;

module.exports = {
// This is a root of the project, ESLint should not look through parent directories to find more config
root: true,
Expand Down Expand Up @@ -77,7 +79,7 @@ module.exports = {
project: './tsconfig.eslint.json',
},
// Allow ESLint to load rules from the TypeScript plugin
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'import-newlines'],
extends: [
// TypeScript plugin's recommended rules
'plugin:@typescript-eslint/recommended',
Expand Down Expand Up @@ -108,6 +110,12 @@ module.exports = {
// NOTE: Consider contributing this to the `airbnb-typescript` config.
'import/named': 'off',
'node/no-missing-import': 'off',
// Enforce how `import`s can be organized across multiple lines / maximum char lengths
'import-newlines/enforce': ['error', {
items: 4, // maximum number of import items per line, but all imports must fit within max-len
'max-len': MAX_LINE_LENGTH, // if imports can be kept to one line AND fit within max-len, great
forceSingleLine: false, // dont force single-line imports as long as the previous two rules are OK
}],

// Prefer an interface declaration over a type alias because interfaces can be extended, implemented, and merged
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
Expand Down Expand Up @@ -169,7 +177,7 @@ module.exports = {
// configurations in both JavaScript and TypeScript.

// Increase the max line length to 120. The rest of this setting is copied from the AirBnB config.
'max-len': ['error', 120, 2, {
'max-len': ['error', MAX_LINE_LENGTH, 2, {
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
Expand Down
7 changes: 4 additions & 3 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@
},
"devDependencies": {
"@microsoft/api-extractor": "^7.36.4",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"chai": "^4.3.8",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-import-newlines": "^1.3.4",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"shx": "^0.3.2",
"ts-node": "^8.2.0",
"sinon": "^15.2.0",
"source-map-support": "^0.5.21",
"ts-node": "^8.2.0",
"typescript": "^4.1.0"
}
}
1 change: 1 addition & 0 deletions packages/oauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"eslint-config-airbnb-base": "^15",
"eslint-config-airbnb-typescript": "^17",
"eslint-plugin-import": "^2",
"eslint-plugin-import-newlines": "^1.3.4",
"eslint-plugin-jsdoc": "^48",
"eslint-plugin-node": "^11",
"mocha": "^10",
Expand Down
1 change: 1 addition & 0 deletions packages/rtm-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-import-newlines": "^1.3.4",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"shx": "^0.3.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/socket-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@
"ws": "^7.5.3"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"chai": "^4.3.8",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-import-newlines": "^1.3.4",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^10.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-import-newlines": "^1.3.4",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"shx": "^0.3.2",
Expand Down
9 changes: 8 additions & 1 deletion packages/types/src/block-kit/block-elements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// This file contains objects documented here: https://api.slack.com/reference/block-kit/block-elements

import { Actionable, Confirmable, Dispatchable, Focusable, Placeholdable, RichTextStyleable } from './extensions';
import {
Actionable,
Confirmable,
Dispatchable,
Focusable,
Placeholdable,
RichTextStyleable,
} from './extensions';
import { Option, PlainTextElement, PlainTextOption } from './composition-objects';
import { RichTextBlock } from './blocks';

Expand Down
24 changes: 23 additions & 1 deletion packages/types/src/block-kit/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@

import { PlainTextElement, MrkdwnElement } from './composition-objects';
import { Actionable } from './extensions';
import { Button, Checkboxes, Datepicker, DateTimepicker, EmailInput, FileInput, ImageElement, MultiSelect, NumberInput, Overflow, PlainTextInput, RadioButtons, Select, Timepicker, URLInput, WorkflowButton, RichTextSection, RichTextList, RichTextQuote, RichTextPreformatted, RichTextInput } from './block-elements';
import {
Button,
Checkboxes,
Datepicker,
DateTimepicker,
EmailInput,
FileInput,
ImageElement,
MultiSelect,
NumberInput,
Overflow,
PlainTextInput,
RadioButtons,
Select,
Timepicker,
URLInput,
WorkflowButton,
RichTextSection,
RichTextList,
RichTextQuote,
RichTextPreformatted,
RichTextInput,
} from './block-elements';

export interface Block {
type: string;
Expand Down
1 change: 1 addition & 0 deletions packages/web-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"eslint-config-airbnb-base": "^15",
"eslint-config-airbnb-typescript": "^17",
"eslint-plugin-import": "^2",
"eslint-plugin-import-newlines": "^1.3.4",
"eslint-plugin-jsdoc": "^48",
"eslint-plugin-node": "^11",
"mocha": "^10",
Expand Down
19 changes: 16 additions & 3 deletions packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,28 @@ import {
} from './types/response';
import { CursorPaginationEnabled } from './types/request/common';
import { Methods } from './methods';
import type { FilesUploadV2Arguments, FileUploadV2Job, FilesGetUploadURLExternalArguments, FilesCompleteUploadExternalArguments } from './types/request/files';
import type {
FilesUploadV2Arguments,
FileUploadV2Job,
FilesGetUploadURLExternalArguments,
FilesCompleteUploadExternalArguments,
} from './types/request/files';
import { getUserAgent } from './instrument';
import {
requestErrorWithOriginal, httpErrorFromResponse, platformErrorFromResult, rateLimitedErrorWithDelay,
requestErrorWithOriginal,
httpErrorFromResponse,
platformErrorFromResult,
rateLimitedErrorWithDelay,
} from './errors';
import { LogLevel, Logger, getLogger } from './logger';
import { RetryOptions, tenRetriesInAboutThirtyMinutes } from './retry-policies';
import delay from './helpers';
import { warnIfNotUsingFilesUploadV2, getFileUploadJob, getMultipleFileUploadJobs, getAllFileUploadsToComplete } from './file-upload';
import {
warnIfNotUsingFilesUploadV2,
getFileUploadJob,
getMultipleFileUploadJobs,
getAllFileUploadsToComplete,
} from './file-upload';

/*
* Helpers
Expand Down
9 changes: 8 additions & 1 deletion packages/web-api/src/file-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { readFileSync } from 'fs';
import { Readable } from 'stream';
import { Logger } from '@slack/logger';
import { errorWithCode, ErrorCode } from './errors';
import { FilesCompleteUploadExternalArguments, FilesUploadV2Arguments, FileUploadBinaryContents, FileUploadStringContents, FileUploadV2, FileUploadV2Job } from './types/request/files';
import {
FilesCompleteUploadExternalArguments,
FilesUploadV2Arguments,
FileUploadBinaryContents,
FileUploadStringContents,
FileUploadV2,
FileUploadV2Job,
} from './types/request/files';

export async function getFileUploadJob(
options: FilesUploadV2Arguments | FileUploadV2,
Expand Down
Loading

0 comments on commit 99b939a

Please sign in to comment.