Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
.nyc_output
coverage
*.code-workspace
/src/config/config.local.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file looks ignored by mistake

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to include this file but in a way that Typescript is happy with if the values are commented out.

12 changes: 12 additions & 0 deletions src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Config } from './configTypes';

const defaultConfig: Config = {
colors: {
broadcastSafe: {
black: '161616',
white: 'EBEBEB'
}
}
};

export default defaultConfig;
25 changes: 25 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import defaultConfig from './config.default';
import { Config } from './configTypes';

let localConfig: Config;

async function loadConfig() {
let config;
try {
const module = await import('./config.local');
config = module.default;
} catch (error) {
config = {};
}
return config;
}

loadConfig().then(config => {
localConfig = config;
}).catch(() => {
console.error('Local configuration file is not defined, using default config');
localConfig = {} as Config;
});

const config: Config = { ...defaultConfig, ...localConfig };
export default config;
12 changes: 12 additions & 0 deletions src/config/configTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface BroadcastSafeColors {
black: string;
white: string;
}

export interface ColorsConfig {
broadcastSafe: BroadcastSafeColors;
}

export interface Config {
colors: ColorsConfig;
}
7 changes: 3 additions & 4 deletions src/createColorValidator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BsDiagnostic, Range } from 'brighterscript';
import { messages } from './plugins/codeStyle/diagnosticMessages';
import config from './config/config';
import { BsLintRules, RuleColorFormat, RuleColorCase, RuleColorAlpha, RuleColorAlphaDefaults, RuleColorCertCompliant } from './index';

export function createColorValidator(severity: Readonly<BsLintRules>) {
Expand Down Expand Up @@ -81,10 +82,8 @@ function validateColorCase(matches: RegExpMatchArray, range: Range, diagnostics:
function validateColorCertCompliance(matches: RegExpMatchArray, range: Range, diagnostics: (Omit<BsDiagnostic, 'file'>)[], colorFormat: RuleColorFormat, certCompliant: RuleColorCertCompliant) {
const validateCertCompliant = certCompliant === 'always';
if (validateCertCompliant && matches) {
const BROADCAST_SAFE_BLACK = '161616';
const BROADCAST_SAFE_WHITE = 'EBEBEB';
const MAX_BLACK_LUMA = getColorLuma(BROADCAST_SAFE_BLACK);
const MAX_WHITE_LUMA = getColorLuma(BROADCAST_SAFE_WHITE);
const MAX_BLACK_LUMA = getColorLuma(config.colors.broadcastSafe.black);
const MAX_WHITE_LUMA = getColorLuma(config.colors.broadcastSafe.white);
let colorValue = matches[0];
const charsToStrip = (colorFormat === 'hash-hex') ? 1 : 2;
colorValue = colorValue.substring(charsToStrip);
Expand Down