包文件→ .shtukbase/packages/std-twelve-factor/checks/tflib.ts
checks/tflib.ts
35 行, 1.9 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // The Twelve-Factor App (https://12factor.net/): the factors a file scan can see — II dependencies, III config,
- // XI logs. The other factors go to a judge.
- import { excluder, list, projectFiles, settings } from './lib/std.ts';
- export const PKG = 'std-twelve-factor';
- export const DEFAULTS = {
- exclude: ['**/fixtures/**', '**/testdata/**', '**/test/**', '**/tests/**', '**/__tests__/**', '**/*.test.*', '**/*.spec.*', '**/*_test.*', '**/*_tests.*', '**/test_*', '**/archive/**', '**/vendor/**', 'docs/**'],
- code: ['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'py', 'rb', 'go', 'rs', 'java', 'kt', 'scala', 'php', 'cs', 'ex', 'exs', 'swift'],
- };
- export function config() {
- const c = settings('twelve-factor', DEFAULTS);
- return { exclude: list(c.exclude), code: list(c.code) };
- }
- /** The project's files minus the excluded ones (tests and fixtures by default: they may hard-code what they like). */
- export function files(): string[] {
- const skip = excluder(config().exclude);
- return projectFiles().filter((f) => !skip(f));
- }
- export function codeFiles(): string[] {
- const exts = new Set(config().code);
- return files().filter((f) => exts.has(f.split('.').pop()?.toLowerCase() ?? ''));
- }
- /** A line that reads the environment: a default next to it is fine. */
- export const READS_ENV = /process\.env|import\.meta\.env|Bun\.env|Deno\.env|os\.environ|os\.getenv|getenv\(|ENV\[|ENV\.fetch|env::var|std::env|System\.getenv|Environment\.GetEnvironmentVariable|env\(|config\(|settings\./;
- /** A comment line (the scan reads code, not prose about code). */
- export const COMMENT = /^\s*(\/\/|#|\*|\/\*|--|;)/;
- /** Hosts reserved for examples and tests (RFC 2606, RFC 6761) and bare placeholder words. */
- export const SAFE_HOST = /^(localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0|host|hostname|server|example)$|(^|\.)(example\.(com|org|net)|example|invalid|test|localhost)$/i;
- export const PLACEHOLDER = /^(pass(word)?|pwd|secret|\*+|x+|changeme|<[^>]*>)$/i;