Skip to content

Commit

Permalink
Lint markdown files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemnmez committed Jul 13, 2023
1 parent a3e425c commit 2a1592a
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@typescript-eslint"
],
"rules": {
"prettier/prettier": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-empty-interface": [
Expand All @@ -47,7 +48,6 @@
"react/self-closing-comp": [ "error" ],
"react/jsx-sort-props": [ "error" ],
"react/no-unescaped-entities": 0,
"prettier/prettier": "error",
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": ["error", { "before": true, "after": true }],
"prefer-const": ["error", { "destructuring": "all" }],
Expand Down
6 changes: 6 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("//ts:rules.bzl", "ts_config")
load("@npm//:renovate/package_json.bzl", "bin")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//md:rules.bzl", "md_files")

package(default_visibility = [":__subpackages__"])

md_files(
name = "markdown_files",
srcs = glob(["**/*.md"])
)

# Useful commands to run!
alias(
name = "fix",
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ I dont care. Tell me about any versions.

## Reporting a Vulnerability

Use this section to tell people how to report a vulnerability.
Use this section to tell people how to report a vulnerability.

[Use the GitHub form](https://github.com/Zemnmez/monorepo/security/advisories/new)
9 changes: 9 additions & 0 deletions bzl/fix_api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
load("//md:rules.bzl", "md_files")

md_files(
name = "markdown_files",
srcs = glob(["**/*.md"])
)

sh_binary(
name = "fix_all",
srcs = ["fix_all.sh"],
)


5 changes: 5 additions & 0 deletions bzl/run_in_workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
load("//rs:rules.bzl", "rust_binary")
load("//md:rules.bzl", "md_files")

package(default_visibility = ["//visibility:public"])

exports_files(["wrapper.template.sh"])

md_files(
name = "markdown_files",
)
2 changes: 1 addition & 1 deletion bzl/run_in_workspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
This is a bazel rule which will take a binary and associated args and deps and proxy it so that
it runs inside the bazel workspace (i.e. the developer's git repo).

By default, 'bazel run \[binary\]' runs in a bazel-specific working directory.
By default, 'bazel run \[binary\]' runs in a bazel-specific working directory.
1 change: 1 addition & 0 deletions md/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
20 changes: 20 additions & 0 deletions md/rules.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("//mdx:rules.bzl", "mdx_lint")

def md_lint(name, srcs = None, **kwargs):
mdx_lint(
name = name,
src = srcs,
**kwargs
)

def md_files(name, srcs = None, **kwargs):
md_lint(
name = name + "_lint",
srcs = srcs
)

native.filegroup(
name = name,
srcs = srcs,
**kwargs
)
23 changes: 23 additions & 0 deletions md/rules.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("//mdx:rules.bzl", "mdx_lint")

def md_lint(name, srcs = None, **kwargs):
mdx_lint(
name = name,
srcs = srcs,
**kwargs
)

def md_files(name, srcs = None, **kwargs):
if srcs == None:
srcs = native.glob(["**/*.md"])

md_lint(
name = name + "_lint",
srcs = srcs
)

native.filegroup(
name = name,
srcs = srcs,
**kwargs
)
6 changes: 6 additions & 0 deletions mdx/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
load("//mdx:rules.bzl", "mdx_files")
load("//md:rules.bzl", "md_files")

md_files(
name = "markdown_files",
srcs = glob(["**/*.md"])
)

mdx_files(
name = "mdx_files",
Expand Down
3 changes: 1 addition & 2 deletions project/ck3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

This directory is for [Crusader Kings 3] mods.


[Crusader Kings 3]: https://ck3.paradoxwikis.com/Crusader_Kings_III_Wiki
[Crusader Kings 3]: https://ck3.paradoxwikis.com/Crusader_Kings_III_Wiki
5 changes: 5 additions & 0 deletions ts/do-sync/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
load("//ts:rules.bzl", "ts_project")
load("//js/npm:rules.bzl", "npm_pkg")
load("//js:rules.bzl", "js_library", "npm_link_package")
load("//md:rules.bzl", "md_files")

package(default_visibility = [
":__subpackages__",
"//deploy:__subpackages__",
])

md_files(
name = "markdown_files"
)

DEPS = [
"//:node_modules/cross-spawn",
"//:node_modules/@types/cross-spawn",
Expand Down
73 changes: 40 additions & 33 deletions ts/do-sync/README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,75 @@
do-sync
========
# do-sync

`do-sync` is a small library that allows certian kinds of async functions to be executed synchronously in node.

Why Though? Isn't this a terrible idea?
---------------------------------------
## Why Though? Isn't this a terrible idea?

`babel-plugin-macros` does not support asynchrony in macros<sup>[1]</sup>, but many vital libraries like `sharp` require asynchrony to function -- and, in fact do not support synchronous usage.

Example
-------
## Example

```typescript
import { doSync, AsyncFn, JSONObject } from 'do-sync';

interface resizeOpts extends JSONObject {
width: number, height: number
width: number;
height: number;
}

interface resizeRet extends JSONObject {
width: number, height: number, blob: string,
width: number;
height: number;
blob: string;
}

const resize = doSync(async (target: string, { width, height, ...jpegOpions }: resizeOpts): Promise<resizeRet> => {
const sharp = require('sharp');
const blob =
(await sharp(Buffer.from(target, 'base64'))
.resize(width, height)
.jpeg(jpegOpions)
.toBuffer()).toString('base64');
return { blob, width, height };
})
const resize = doSync(
async (
target: string,
{ width, height, ...jpegOpions }: resizeOpts
): Promise<resizeRet> => {
const sharp = require('sharp');
const blob = (
await sharp(Buffer.from(target, 'base64'))
.resize(width, height)
.jpeg(jpegOpions)
.toBuffer()
).toString('base64');
return { blob, width, height };
}
);

const myImage = resize('cool.png', {
width: 10, height: 10
})
width: 10,
height: 10,
});
```

This package is used to implement [image.macro], which dynamically resizes high-resolution images to multiple sizes at compilation time for use with webpack. It's a little rough around the edges, but works well and should provide some more concrete usage examples:

- [do-sync function definition](https://github.com/Zemnmez/image.macro/blob/master/src/resize.ts#L41)
- [usage in macro](https://github.com/Zemnmez/image.macro/blob/ab403a25ca517da8cb749d11c9248479beaebd71/src/image.macro.ts#L84)
- [do-sync function definition](https://github.com/Zemnmez/image.macro/blob/master/src/resize.ts#L41)
- [usage in macro](https://github.com/Zemnmez/image.macro/blob/ab403a25ca517da8cb749d11c9248479beaebd71/src/image.macro.ts#L84)

Limitations
-----------
- The function will be completely extracted from its scope context. It is run as though it was on its own, in its own file.
- Only JSON serializible parameters and response values are allowed.
- Typescript will enforce JSON serializibility, but as a result
pure `Object`s passed into functions, or returned by functions must extend
or implement JSONObject.
- If the process throws an error, properties that cannot be serialized to JSON will not cross the process boundary.
## Limitations

- The function will be completely extracted from its scope context. It is run as though it was on its own, in its own file.
- Only JSON serializible parameters and response values are allowed.
- Typescript will enforce JSON serializibility, but as a result
pure `Object`s passed into functions, or returned by functions must extend
or implement JSONObject.
- If the process throws an error, properties that cannot be serialized to JSON will not cross the process boundary.

[1]: https://github.com/kentcdodds/babel-plugin-macros/issues/62#issuecomment-387155622

## Footguns

Footguns
--------
### ENOBUFS

`do-sync` uses a node subprocess and writes all code to STDIN. `child_process.spawnSync` has a default limit on STDIN input which can, if large JSON is transiting STDIN make your program explode. `doSync` takes an optional second parameter, `opts`, which has the same options as `spawnSync` -- the value is already very large (1GB), but you can set maxBuffer to something bigger if you encounter issues:

```typescript
doSync(myFunc, {
maxBuffer: 1024 * 1024 * 1024
})
maxBuffer: 1024 * 1024 * 1024,
});
```

[image.macro]: https://github.com/Zemnmez/image.macro/blob/ab403a25ca517da8cb749d11c9248479beaebd71/src/resize.ts
Expand Down
8 changes: 8 additions & 0 deletions ts/knowitwhenyouseeit/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
load("//ts:rules.bzl", "jest_test", "ts_project")
load("//js/npm:rules.bzl", "npm_pkg")
load("//md:rules.bzl", "md_files")

package(default_visibility = [
"//deploy:__subpackages__",
])


md_files(
name = "markdown_files",
srcs = glob(["**/*.md"])
)


ts_project(
name = "project",
srcs = [
Expand Down
14 changes: 6 additions & 8 deletions ts/knowitwhenyouseeit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ yarn add knowitwhenyouseeit
## Usage

```jsx
import allowlisted from 'knowitwhenyouseeit'
import allowlisted from 'knowitwhenyouseeit';

const getMessage = allowllisted(
"$2y$12$BcuZ0VfUeLLpoLxOC5Xv7eQQK0r95by8YJsECCldKP4ftPr20rpXW", //hello world
"$2y$12$hxyWxMx.qap70Snn1QKMwuDp/9XgNM7HpwbrGnsPu/j7dyTEWh0M2" //hewwo world
)

getMessage("helllo world!") // false
getMessage("hello world") // "hello world"

'$2y$12$BcuZ0VfUeLLpoLxOC5Xv7eQQK0r95by8YJsECCldKP4ftPr20rpXW', //hello world
'$2y$12$hxyWxMx.qap70Snn1QKMwuDp/9XgNM7HpwbrGnsPu/j7dyTEWh0M2' //hewwo world
);

getMessage('helllo world!'); // false
getMessage('hello world'); // "hello world"
```

## License
Expand Down

0 comments on commit 2a1592a

Please sign in to comment.