Skip to content

Commit

Permalink
feat: Update for deprecated @ syntax in mkosi files
Browse files Browse the repository at this point in the history
  • Loading branch information
hangxingliu committed Jan 1, 2025
1 parent f3ebe2a commit 0dc2b0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
23 changes: 23 additions & 0 deletions docs/SYSTEMD-SYNTAX.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ Key=line1
line2
Key2=val # Comment
```

### Deprecated `@` "Default Value" Syntax

Old:

> <https://github.com/systemd/mkosi/blob/8aefea6923dd049d060eea7e88f9054b674b432e/mkosi/resources/mkosi.md>
>
> If a setting's name in the configuration file is prefixed with `@`,
> it configures the default value used for that setting if no explicit default value is set.
> This can be used to set custom default values in configuration files that can still be overridden by
> specifying the setting explicitly via the CLI.

They removed it in the commit [1b8f7f240dfdc85bc7bdf2b3aea3c590d2203eba](https://github.com/systemd/mkosi/commit/1b8f7f240dfdc85bc7bdf2b3aea3c590d2203eba):

> Note that settings configured via the command line always override
> settings configured via configuration files. If the same setting is
> configured more than once via configuration files, later assignments
> override earlier assignments except for settings that take a collection
> of values. Also, settings read from `mkosi.local.conf` will override
> settings from configuration files that are parsed later but not settings
> specified on the CLI.
9 changes: 7 additions & 2 deletions src/vscode-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export class SystemdLint implements CodeActionProvider {
const { customDirectiveKeys, customDirectiveRegexps } = config;
const fileType = this.documents.getType(document);

const opts: CommonOptions = { mkosi: fileType === SystemdFileType.mkosi };
const mkosiMode = fileType === SystemdFileType.mkosi
const opts: CommonOptions = { mkosi: mkosiMode };
const { tokens } = tokenizer(document.getText(), opts);
const dirs = getDirectivesFromTokens(tokens);
// console.log("lintDocument", dirs);
Expand All @@ -123,8 +124,12 @@ export class SystemdLint implements CodeActionProvider {
dirs.forEach((it) => {
if (!it.key) return;

const directiveName = it.key.trim();
let directiveName = it.key.trim();
// compatible with the old mkosi `@` syntax (they have removed it)
if (mkosiMode && directiveName.startsWith('@'))
directiveName = directiveName.slice(1);
const directiveNameLC = directiveName.toLowerCase();

//#region lint by name
if (directiveNameLC.startsWith("x-")) return;
if (directiveNameLC.startsWith("-")) return;
Expand Down

0 comments on commit 0dc2b0f

Please sign in to comment.