Skip to content

Commit

Permalink
Enable TS strict and noUncheckedIndexAccess (#49)
Browse files Browse the repository at this point in the history
* wip

* actions/setup-node cache option is broken for yarn v4

* Remove comments

* update test
  • Loading branch information
nickrttn authored Nov 28, 2023
1 parent dfb666c commit cb637ef
Show file tree
Hide file tree
Showing 30 changed files with 150 additions and 140 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-monolib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- run: corepack yarn --immutable
- run: corepack yarn test
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"@babel/eslint-parser": "^7.18.9",
"@babel/eslint-plugin": "^7.18.10",
"@sucrase/jest-plugin": "^2.2.1",
"@types/inflection": "^1.13.1",
"@types/inflection": "^1.13.2",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"@types/node": "^18.18.13",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-transloadit": "^2.0.0",
Expand All @@ -58,6 +58,6 @@
"prettier": "^2.8.6",
"replace-require-with-import": "^2.1.0",
"sucrase": "^3.25.0",
"typescript": "^4.8.2"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/abbr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/abbr"
},
"main": "dist/abbr.js",
"typings": "dist/abbr.d.ts",
"types": "dist/abbr.d.ts",
"files": [
"dist"
],
Expand Down
6 changes: 3 additions & 3 deletions packages/analyze-step/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/analyze-step"
},
"main": "dist/analyzeStep.js",
"typings": "dist/analyzeStep.d.ts",
"types": "dist/analyzeStep.d.ts",
"files": [
"dist"
],
Expand All @@ -32,7 +32,7 @@
"version": "0.1.3",
"gitHead": "b73ab4880b9c4c48db32f249f776974a137510c4",
"devDependencies": {
"@types/jsonpath": "^0.2.0",
"@types/lodash": "^4"
"@types/jsonpath": "^0.2.4",
"@types/lodash": "^4.14.202"
}
}
34 changes: 19 additions & 15 deletions packages/analyze-step/src/analyzeStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function humanJoin(array: string[], reduce = true, glueword = 'and'): string {
}
}

if (countedArray.length === 1) {
if (countedArray.length === 1 && typeof countedArray[0] === 'string') {
return countedArray[0]
}

Expand Down Expand Up @@ -67,9 +67,9 @@ function humanFilter(step: FileFilterStep): string {
for (const type of types) {
collection[type] = collection[type] || []
if (typeof step[type] === 'string') {
collection[type].push(`Filter by code evaluation`)
collection[type]?.push(`Filter by code evaluation`)
} else if (step[type] && Array.isArray(step[type])) {
for (const [key, operator, val] of Object.values(step[type])) {
for (const [key, operator, val] of Object.values(step[type]!)) {

Check warning on line 72 in packages/analyze-step/src/analyzeStep.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion
const template = clone(templates[operator])
if (!template) {
throw new Error(
Expand Down Expand Up @@ -145,7 +145,7 @@ function humanFilter(step: FileFilterStep): string {
humanDescr = humanDescr.replace('wi2th', 'with')
}

collection[type].push(humanDescr)
collection[type]?.push(humanDescr)
lastTemplate = template
}
}
Expand Down Expand Up @@ -211,11 +211,11 @@ function humanDimensions(step: StepWithDimensions): string {

if ('width' in step && 'height' in step) {
str += ` to ${step.width}×${step.height}`
} else if ('width' in step) {
} else if (step.width) {
str += ` to ${step.width} pixels wide`
} else if ('height' in step) {
} else if (step.height) {
str += ` to ${step.height} pixels high`
} else if ('crop' in step) {
} else if (step.crop) {
str += ` to ${step.crop.x2 - step.crop.x1}×${step.crop.y2 - step.crop.y1} starting at ${
step.crop.x1
}×${step.crop.y1} from the top left`
Expand All @@ -233,6 +233,8 @@ type ExtraMeta = {
}

function humanPreset(step: PresetStep, extrameta: ExtraMeta = {}): string {
if (!step.preset) return ''

let str = inflect.humanize(step.preset.replace(/[-_]/g, ' '))

if (str.match(/^ipad/i)) {
Expand Down Expand Up @@ -278,6 +280,8 @@ type FormatStep = {
}

function humanFormat(step: FormatStep): string {
if (!step.format) return ''

let str = inflect.humanize(step.format.replace(/[-_]/g, ' '))

if (str.match(/^webp/i)) {
Expand Down Expand Up @@ -309,9 +313,9 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
let str = ``

const robot = robots[step.robot]
str = robot.purpose_words
str = robot?.purpose_words ?? ''

if (robot.rname === '/video/encode') {
if (robot?.rname === '/video/encode') {
if (JSON.stringify(step).match(/watermark/)) {
str = `Watermark videos`
} else if (get(step, 'ffmpeg.t') && get(step, 'ffmpeg.ss')) {
Expand Down Expand Up @@ -358,7 +362,7 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/audio/encode') {
if (robot?.rname === '/audio/encode') {
if (has(step, 'ffmpeg.ss') && has(step, 'ffmpeg.t')) {
str = `Take a ${get(step, 'ffmpeg.t')}s clip out of audio at a specified offset`
} else if (
Expand All @@ -382,15 +386,15 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/video/adaptive') {
if (robot?.rname === '/video/adaptive') {
if (step.technique === 'hls') {
str = `Convert videos to HLS`
} else if (step.technique === 'dash') {
str = `Convert videos to MPEG-Dash`
}
}

if (robot.rname === '/video/merge') {
if (robot?.rname === '/video/merge') {
const types = JSONPath({ path: '$..as', json: step })
if (types.length) {
str = `Merge ${humanJoin(types)} to create a new video`
Expand All @@ -399,19 +403,19 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/file/filter') {
if (robot?.rname === '/file/filter') {
str = humanFilter(step as FileFilterStep)
}

if (robot.rname === '/audio/artwork') {
if (robot?.rname === '/audio/artwork') {
if (get(step, 'method') === 'insert') {
str = `Insert audio artwork`
} else {
str = `Extract audio artwork`
}
}

if (robot.rname === '/image/resize') {
if (robot?.rname === '/image/resize') {
if ('watermark_url' in step) {
str = `Watermark images`
} else if ('sepia' in step) {
Expand Down
4 changes: 2 additions & 2 deletions packages/enrich-tweet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/enrich-tweet"
},
"main": "dist/enrichTweet.js",
"typings": "dist/enrichTweet.d.ts",
"types": "dist/enrichTweet.d.ts",
"files": [
"dist"
],
Expand All @@ -31,6 +31,6 @@
"twitter-text": "^3.1.0"
},
"devDependencies": {
"@types/twitter-text": "^3.1.2"
"@types/twitter-text": "^3.1.9"
}
}
40 changes: 20 additions & 20 deletions packages/enrich-tweet/src/enrichTweet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,88 @@ import enrichTweet from './enrichTweet'

describe('enrichTweet', () => {
test('should render tweet 1087761082247204900 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-1087761082247204900.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`In the age of cloud, <a class="tweet-url username" href="https://twitter.com/transloadit" data-screen-name="transloadit" rel="nofollow">@transloadit</a> shows great balance of leaning on larger clouds while managing infra in-house <a class="tweet-url username" href="https://twitter.com/kvz" data-screen-name="kvz" rel="nofollow">@kvz</a> \n<a href="https://transloadit.com/blog/2018/12/launching-asia-pacific-and-network-changes/" rel="nofollow">https://transloadit.com/blog/2018/12/launching-asia-pacific-and-network-changes/</a> \n\n<a href="https://pbs.twimg.com/media/DxiA8ElX4AA4hQ6.jpg" rel="nofollow"><img class="tweet-media" src="https://pbs.twimg.com/media/DxiA8ElX4AA4hQ6.jpg" /></a>`
)
})
}, 20000)

test('should render tweet 1082897509528281089 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-1082897509528281089.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`Just realized how <a class="tweet-url username" href="https://twitter.com/tus_io" data-screen-name="tus_io" rel="nofollow">@tus_io</a> and <a class="tweet-url username" href="https://twitter.com/uppy_io" data-screen-name="uppy_io" rel="nofollow">@uppy_io</a> are a perfect example of <a class="tweet-url username" href="https://twitter.com/transloadit" data-screen-name="transloadit" rel="nofollow">@transloadit</a> commoditizing their complements: <a href="https://gwern.net/complement" rel="nofollow">https://gwern.net/complement</a>`
)
})
}, 20000)

test('should render tweet 389922139408592896 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-389922139408592896.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`Don't understand why anyone messes with carrierwave / paperclip / whatever anymore. <a class="tweet-url username" href="https://twitter.com/transloadit" data-screen-name="transloadit" rel="nofollow">@transloadit</a> is just too easy. <a href="https://transloadit.com/r/wGN" rel="nofollow">https://transloadit.com/r/wGN</a>`
)
})
}, 20000)

test('should render tweet 558414704024899584 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-558414704024899584.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`Thank the sponsors! <a href="http://2015.staticshowdown.com/sponsors" rel="nofollow">http://2015.staticshowdown.com/sponsors</a> <a class="tweet-url username" href="https://twitter.com/polymer" data-screen-name="polymer" rel="nofollow">@polymer</a> <a class="tweet-url username" href="https://twitter.com/BloombergBeta" data-screen-name="BloombergBeta" rel="nofollow">@BloombergBeta</a> <a class="tweet-url username" href="https://twitter.com/Firebase" data-screen-name="Firebase" rel="nofollow">@Firebase</a> <a class="tweet-url username" href="https://twitter.com/MaxCDNDeveloper" data-screen-name="MaxCDNDeveloper" rel="nofollow">@MaxCDNDeveloper</a> <a class="tweet-url username" href="https://twitter.com/sprintly" data-screen-name="sprintly" rel="nofollow">@sprintly</a> <a class="tweet-url username" href="https://twitter.com/dropboxapi" data-screen-name="dropboxapi" rel="nofollow">@dropboxapi</a> <a class="tweet-url username" href="https://twitter.com/codeship" data-screen-name="codeship" rel="nofollow">@codeship</a> <a class="tweet-url username" href="https://twitter.com/transloadit" data-screen-name="transloadit" rel="nofollow">@transloadit</a>`
)
})
}, 20000)

test('should render tweet 647088863777832961 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-647088863777832961.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`SponsorOfTheDay! We have giant love feelings for <a class="tweet-url username" href="https://twitter.com/transloadit" data-screen-name="transloadit" rel="nofollow">@transloadit</a>! And not just cuz that logo's cute as a bug. Thank you! \n\n<a href="https://pbs.twimg.com/media/CPrr5KQWwAAin58.png" rel="nofollow"><img class="tweet-media" src="https://pbs.twimg.com/media/CPrr5KQWwAAin58.png" /></a>`
)
})
}, 20000)

test('should render tweet 588610060810526720 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-588610060810526720.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`Trying to process/thumbnail about 600k avatars in a few hours. Thank you <a class="tweet-url username" href="https://twitter.com/transloadit" data-screen-name="transloadit" rel="nofollow">@transloadit</a> <a class="tweet-url username" href="https://twitter.com/Prezly" data-screen-name="Prezly" rel="nofollow">@Prezly</a> \n\n<a href="https://pbs.twimg.com/ext_tw_video_thumb/588609941604171776/pu/img/657mRahs1TNqS0vw.jpg" rel="nofollow"><img class="tweet-media" src="https://pbs.twimg.com/ext_tw_video_thumb/588609941604171776/pu/img/657mRahs1TNqS0vw.jpg" /></a>`
)
})
}, 20000)

test('should render tweet 17139572739674112 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-17139572739674112.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`Encode your videos faster ! nice piece of technology : <a href="https://transloadit.com/blog/2010/12/realtime-encoding-over-150x-faster/" rel="nofollow">https://transloadit.com/blog/2010/12/realtime-encoding-over-150x-faster/</a> <a href="https://twitter.com/search?q=%23video" title="#video" class="tweet-url hashtag" rel="nofollow">#video</a> <a href="https://twitter.com/search?q=%23encoding" title="#encoding" class="tweet-url hashtag" rel="nofollow">#encoding</a>`
)
})
}, 20000)

test('should render tweet 16955922978971648 correctly', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-16955922978971648.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
`Hey <a class="tweet-url username" href="https://twitter.com/YouTube" data-screen-name="YouTube" rel="nofollow">@YouTube</a>, <a class="tweet-url username" href="https://twitter.com/vimeo" data-screen-name="vimeo" rel="nofollow">@vimeo</a> and other video upload/sharing sites, offer <a class="tweet-url username" href="https://twitter.com/transloadit" data-screen-name="transloadit" rel="nofollow">@transloadit</a> a lot of money, now, quick <a href="https://news.ycombinator.com/item?id=2025354" rel="nofollow">https://news.ycombinator.com/item?id=2025354</a>`
)
})
}, 20000)

test('should not explode on undefined', async () => {
jest.setTimeout(20000)
// @ts-expect-error - testing invalid input
expect(await enrichTweet(undefined)).toBe(undefined)
})
}, 20000)

test('should not hang on non-shortened urls', async () => {
jest.setTimeout(20000)
const tweet = JSON.parse(
fs.readFileSync(`${__dirname}/enrichTweet.fixture-1087761082247204900-2.json`, 'utf-8')
)
expect(await enrichTweet(tweet)).toBe(
'<a href="https://twitter.com/TLStatus/status/1365465781467836417" rel="nofollow">https://twitter.com/TLStatus/status/1365465781467836417</a>'
)
})
}, 20000)
})
2 changes: 1 addition & 1 deletion packages/enrich-tweet/src/enrichTweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function enrichTweet(
): Promise<string | undefined> {
if (!tweet) return

let text = tweet.full_text
let text = tweet.full_text ?? ''

// Expand URLs
if (tweet.entities && tweet.entities.urls.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/file-exists/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/file-exists"
},
"main": "dist/fileExists.js",
"typings": "dist/fileExists.d.ts",
"types": "dist/fileExists.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/format-duration-ms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/format-duration-ms"
},
"main": "dist/formatDurationMs.js",
"typings": "dist/formatDurationMs.d.ts",
"types": "dist/formatDurationMs.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/has-property/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/has-property"
},
"main": "dist/has-property.js",
"typings": "dist/has-property.d.ts",
"types": "dist/has-property.d.ts",
"files": [
"dist"
],
Expand Down
6 changes: 3 additions & 3 deletions packages/post/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/post"
},
"bin": "./post.js",
"typings": "dist/post.d.ts",
"types": "dist/post.d.ts",
"files": [
"dist"
],
Expand All @@ -32,7 +32,7 @@
"version": "0.1.3",
"gitHead": "b73ab4880b9c4c48db32f249f776974a137510c4",
"devDependencies": {
"@types/inquirer": "^8.2.1",
"@types/title": "^3.4.1"
"@types/inquirer": "^8.2.10",
"@types/title": "^3.4.3"
}
}
4 changes: 3 additions & 1 deletion packages/post/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ async function post(): Promise<void> {
throw new Error(`Dir does not exist: '${postDir.replace(process.cwd(), '.')}'`)
}

const mysqlNow = new Date().toISOString().replace('T', ' ').split('.')[0].split(' ')[0]
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const mysqlNow = new Date().toISOString().replace('T', ' ').split('.')[0]!.split(' ')[0]!

// eslint-disable-next-line no-unused-vars
const [dateY, datem] = mysqlNow.split('-')
const answers = await inquirer.prompt([
Expand Down
2 changes: 1 addition & 1 deletion packages/pr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/pr"
},
"main": "dist/pr.js",
"typings": "dist/pr.d.ts",
"types": "dist/pr.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/prd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/prd"
},
"main": "dist/prd.js",
"typings": "dist/prd.d.ts",
"types": "dist/prd.d.ts",
"files": [
"dist"
],
Expand Down
Loading

0 comments on commit cb637ef

Please sign in to comment.