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

Add linting rule to sort imports #3220

Open
wants to merge 7 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/olive-teachers-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Support environemnts not providing URL.canParse
71 changes: 56 additions & 15 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,48 +1,89 @@
{
"root": true,
// parse TypeScript files
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser
"parser": "@typescript-eslint/parser",
// configure eslint using options described at
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/base",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier"
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
],
"plugins": ["n"],
"ignorePatterns": ["dist", "node_modules"],
"rules": {
"no-var": "error",
"prefer-const": "warn",
"no-misleading-character-class": "warn",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"n/global-require": "error",
"n/no-extraneous-import": [
"error",
{ "allowModules": ["@atproto/dev-env"] },
],
"n/prefer-node-protocol": "error",
"import/export": "off",
"import/namespace": "off",
"import/order": [
"error",
{
"named": true,
"distinctGroup": true,
"alphabetize": { "order": "asc" },
"newlines-between": "always",
"groups": [
"builtin",
"external",
"internal",
"parent",
["index", "sibling"],
"object",
],
},
],
"@typescript-eslint/no-unused-vars": [
"warn",
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" },
],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
},
"overrides": [
{
"files": ["jest.config.js"],
"env": { "commonjs": true }
"env": { "commonjs": true },
},
{
"files": ["jest.setup.js"],
"env": { "jest": true }
"env": { "jest": true },
},
{
"files": "*.js",
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
"@typescript-eslint/no-var-requires": "off",
},
},
],
"settings": {
"node": { "version": ">=18.7.0" },
"import/internal-regex": "^@atproto/",
"import/parsers": { "@typescript-eslint/parser": [".ts", ".tsx"] },
"import/resolver": {
"typescript": {
"project": [
"tsconfig.json",
"packages/oauth/*/tsconfig.json",
"packages/internal/*/tsconfig.json",
"packages/*/tsconfig.json",
],
},
"node": {
"extensions": [".js", ".jsx", ".json"],
},
},
},
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"private": true,
"engines": {
"node": ">=18"
"node": ">=18.7.0"
},
"packageManager": "[email protected]",
"scripts": {
Expand Down Expand Up @@ -42,6 +42,9 @@
"dotenv": "^16.0.3",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.15.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^28.1.2",
"node-gyp": "^9.3.1",
Expand Down
9 changes: 0 additions & 9 deletions packages/api/bench/agent.bench.ts

This file was deleted.

15 changes: 6 additions & 9 deletions packages/api/src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import AwaitLock from 'await-lock'

import { TID } from '@atproto/common-web'
import { AtUri, ensureValidDid } from '@atproto/syntax'
import {
buildFetchHandler,
BuildFetchHandlerOptions,
FetchHandler,
XrpcClient,
} from '@atproto/xrpc'
import AwaitLock from 'await-lock'
import { FetchHandler, XrpcClient, buildFetchHandler } from '@atproto/xrpc'

import {
AppBskyActorDefs,
AppBskyActorProfile,
Expand Down Expand Up @@ -38,14 +35,14 @@ import {
BskyThreadViewPreference,
} from './types'
import {
asDid,
Did,
asDid,
getSavedFeedType,
isDid,
sanitizeMutedWordValue,
savedFeedsToUriArrays,
validateSavedFeed,
validateNux,
validateSavedFeed,
} from './util'

const FEED_VIEW_PREF_DEFAULTS = {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/atp-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
XrpcClient,
errorResponseBody,
} from '@atproto/xrpc'

import { Agent } from './agent'
import {
ComAtprotoServerCreateAccount,
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Lexicons } from '@atproto/lexicon'

import { lexicons as internalLexicons } from './client/lexicons'

export { AtUri } from '@atproto/syntax'
export {
BlobRef,
jsonStringToLex,
jsonToLex,
lexToJson,
stringifyLex,
jsonToLex,
jsonStringToLex,
} from '@atproto/lexicon'
export { parseLanguage } from '@atproto/common-web'
export * from './types'
Expand All @@ -22,7 +23,7 @@ export * from './rich-text/util'
export * from './moderation'
export * from './moderation/types'
export * from './mocker'
export { LABELS, DEFAULT_LABEL_SETTINGS } from './moderation/const/labels'
export { DEFAULT_LABEL_SETTINGS, LABELS } from './moderation/const/labels'
export { Agent } from './agent'

export { AtpAgent, type AtpAgentOptions } from './atp-agent'
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/mocker.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
ComAtprotoLabelDefs,
AppBskyFeedDefs,
AppBskyActorDefs,
AppBskyFeedPost,
AppBskyEmbedRecord,
AppBskyFeedDefs,
AppBskyFeedPost,
AppBskyGraphDefs,
AppBskyNotificationListNotifications,
ComAtprotoLabelDefs,
} from './client'

const FAKE_CID = 'bafyreiclp443lavogvhj3d2ob2cxbfuscni2k5jk7bebjzg7khl3esabwq'
Expand Down
15 changes: 8 additions & 7 deletions packages/api/src/moderation/decision.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { AppBskyGraphDefs } from '../client/index'

import { LABELS } from './const/labels'
import {
BLOCK_BEHAVIOR,
MUTE_BEHAVIOR,
MUTEWORD_BEHAVIOR,
CUSTOM_LABEL_VALUE_RE,
HIDE_BEHAVIOR,
NOOP_BEHAVIOR,
Label,
LabelPreference,
ModerationCause,
ModerationOpts,
LabelTarget,
MUTEWORD_BEHAVIOR,
MUTE_BEHAVIOR,
ModerationBehavior,
CUSTOM_LABEL_VALUE_RE,
ModerationCause,
ModerationOpts,
NOOP_BEHAVIOR,
} from './types'
import { ModerationUI } from './ui'
import { LABELS } from './const/labels'

enum ModerationBehaviorSeverity {
High,
Expand Down
22 changes: 11 additions & 11 deletions packages/api/src/moderation/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {
ModerationSubjectProfile,
ModerationSubjectPost,
ModerationSubjectNotification,
ModerationSubjectFeedGenerator,
ModerationSubjectUserList,
ModerationOpts,
} from './types'
import { ModerationDecision } from './decision'
import { decideAccount } from './subjects/account'
import { decideProfile } from './subjects/profile'
import { decideFeedGenerator } from './subjects/feed-generator'
import { decideNotification } from './subjects/notification'
import { decidePost } from './subjects/post'
import { decideFeedGenerator } from './subjects/feed-generator'
import { decideProfile } from './subjects/profile'
import { decideUserList } from './subjects/user-list'
import { ModerationDecision } from './decision'
import {
ModerationOpts,
ModerationSubjectFeedGenerator,
ModerationSubjectNotification,
ModerationSubjectPost,
ModerationSubjectProfile,
ModerationSubjectUserList,
} from './types'

export { ModerationUI } from './ui'
export { ModerationDecision } from './decision'
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/moderation/subjects/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModerationDecision } from '../decision'
import { Label, ModerationSubjectProfile, ModerationOpts } from '../types'
import { Label, ModerationOpts, ModerationSubjectProfile } from '../types'

export function decideAccount(
subject: ModerationSubjectProfile,
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/moderation/subjects/feed-generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ModerationDecision } from '../decision'
import { ModerationSubjectFeedGenerator, ModerationOpts } from '../types'
import { ModerationOpts, ModerationSubjectFeedGenerator } from '../types'

import { decideAccount } from './account'
import { decideProfile } from './profile'

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/moderation/subjects/notification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ModerationDecision } from '../decision'
import { ModerationSubjectNotification, ModerationOpts } from '../types'
import { ModerationOpts, ModerationSubjectNotification } from '../types'

import { decideAccount } from './account'
import { decideProfile } from './profile'

Expand Down
11 changes: 6 additions & 5 deletions packages/api/src/moderation/subjects/post.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ModerationDecision } from '../decision'
import {
AppBskyFeedPost,
AppBskyActorDefs,
AppBskyEmbedExternal,
AppBskyEmbedImages,
AppBskyEmbedRecord,
AppBskyEmbedRecordWithMedia,
AppBskyEmbedExternal,
AppBskyActorDefs,
AppBskyFeedPost,
} from '../../client'
import { ModerationSubjectPost, ModerationOpts } from '../types'
import { ModerationDecision } from '../decision'
import { hasMutedWord } from '../mutewords'
import { ModerationOpts, ModerationSubjectPost } from '../types'

import { decideAccount } from './account'
import { decideProfile } from './profile'

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/moderation/subjects/profile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModerationDecision } from '../decision'
import { Label, ModerationSubjectProfile, ModerationOpts } from '../types'
import { Label, ModerationOpts, ModerationSubjectProfile } from '../types'

export function decideProfile(
subject: ModerationSubjectProfile,
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/moderation/subjects/user-list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AtUri } from '@atproto/syntax'

import { AppBskyActorDefs } from '../../client/index'
import { ModerationDecision } from '../decision'
import { ModerationSubjectUserList, ModerationOpts } from '../types'
import { ModerationOpts, ModerationSubjectUserList } from '../types'

import { decideAccount } from './account'
import { decideProfile } from './profile'

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/moderation/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
AppBskyActorDefs,
AppBskyFeedDefs,
AppBskyNotificationListNotifications,
AppBskyGraphDefs,
AppBskyNotificationListNotifications,
ComAtprotoLabelDefs,
} from '../client/index'

import { KnownLabelValue } from './const/labels'

// syntax
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/moderation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
AppBskyLabelerDefs,
ComAtprotoLabelDefs,
} from '../client'

import {
InterpretedLabelValueDefinition,
ModerationBehavior,
LabelPreference,
LabelValueDefinitionFlag,
ModerationBehavior,
} from './types'

export function isQuotedPost(embed: unknown): embed is AppBskyEmbedRecord.View {
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/rich-text/detection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import TLDs from 'tlds'

import { AppBskyRichtextFacet } from '../client'

import { UnicodeString } from './unicode'
import {
URL_REGEX,
MENTION_REGEX,
TAG_REGEX,
TRAILING_PUNCTUATION_REGEX,
URL_REGEX,
} from './util'

export type Facet = AppBskyRichtextFacet.Main
Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/rich-text/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ F: 0 1 2 3 4 5 6 7 8 910 // string indices
*/

import { AppBskyFeedPost, AppBskyRichtextFacet, AtpBaseClient } from '../client'
import { UnicodeString } from './unicode'
import { sanitizeRichText } from './sanitization'

import { detectFacets } from './detection'
import { sanitizeRichText } from './sanitization'
import { UnicodeString } from './unicode'

export type Facet = AppBskyRichtextFacet.Main
export type FacetLink = AppBskyRichtextFacet.Link
Expand Down
Loading
Loading