@averay/codeformat
v0.4.6
Published
A very opinionated collection of configurations for a number of code formatting tools.
Readme
@averay/codeformat
A very opinionated collection of configurations for a number of code formatting tools.
Default Usage
Install Vite+ and this package with
vp i -D @averay/codeformat.Symlink the static configuration files to the project root:
ln -s node_modules/@averay/codeformat/.editorconfig ./Import and call the relevant configuration builders for specific tools
Lint the codebase with
vpx codeformat check, or apply automatic fixes withvpx codeformat fix
Vite+ Format (via Oxfmt)
Create a vite.config.ts file, or generate one programmatically:
// vite.config.ts
import { makeOxfmtConfig } from '@averay/codeformat';
import { defineConfig } from 'vite-plus';
export default defineConfig({
fmt: makeOxfmtConfig(/* Customisations can be made here */),
});Vite+ Lint (via Oxlint)
Create an oxlint.config.ts file with the following configuration:
// vite.config.ts
import { makeOxlintConfig } from '@averay/codeformat';
import { defineConfig } from 'vite-plus';
export default defineConfig({
lint: makeOxlintConfig({ tsconfigPath: './tsconfig.json' }),
});Stylelint
Create a stylelint.config.ts file with the following configuration:
// stylelint.config.ts
import { makeStylelintConfig } from '@averay/codeformat';
export default makeStylelintConfig();Knip
Create a knip.config.ts file with the following configuration:
// knip.config.ts
import type { KnipConfig } from 'knip';
export default {
entry: ['src/index.ts'],
project: ['src/**/*.ts'],
} satisfies KnipConfig;DCLint
Create a dclint.config.ts file with the following configuration:
// dclint.config.ts
import { makeDclintConfig } from '@averay/codeformat';
const config = makeDclintConfig(/* Optional customisations */);
export { config as 'module.exports' }; // Must be exported with this syntaxMago (PHP)
Create a mago.toml file with the following configuration:
#:schema vendor/carthage-software/mago/schema.json
extends = "node_modules/@averay/codeformat/mago.base.toml"
[source]
paths = ["."]PHP-CS-Fixer (PHP)
Configure autoloading utility in composer.json:
{
// ...
"autoload-dev": {
"files": ["node_modules/@averay/codeformat/autoload.php"]
}
// ...
}Then, create a .php-cs-fixer.dist.php file with the following configuration:
<?php
declare(strict_types=1);
$finder = new PhpCsFixer\Finder()->in([__DIR__])->exclude(['node_modules', 'vendor']);
return Averay\Codeformat\PhpCsFixerConfig::default($finder);swift-format (Swift)
Symlink the configuration file to the project root:
ln -s node_modules/@averay/codeformat/.swift-format ./