Skip to content

Commit 0fe0e5e

Browse files
authored
Merge pull request #262 from vim-denops/asconst
👍 change array argument types to readonly
2 parents dae0f5e + 38bb82b commit 0fe0e5e

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

argument/flags.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const shortPattern = /^-([a-zA-Z0-9])(.*)/;
3333
* }
3434
* ```
3535
*/
36-
export function parseFlags(args: string[]): [Flags, string[]] {
36+
export function parseFlags(args: readonly string[]): [Flags, string[]] {
3737
const patterns = [longPattern, shortPattern];
3838
const flags: Flags = {};
3939
const residue: string[] = [];
@@ -86,7 +86,10 @@ export function parseFlags(args: string[]): [Flags, string[]] {
8686
* }
8787
* ```
8888
*/
89-
export function validateFlags(flags: Flags, knownAttributes: string[]): void {
89+
export function validateFlags(
90+
flags: Flags,
91+
knownAttributes: readonly string[],
92+
): void {
9093
Object.keys(flags).forEach((v) => {
9194
if (!knownAttributes.includes(v)) {
9295
if (v.length === 1) {
@@ -116,7 +119,7 @@ export function validateFlags(flags: Flags, knownAttributes: string[]): void {
116119
*/
117120
export function formatFlag(
118121
key: string,
119-
value: string | string[] | undefined,
122+
value: string | readonly string[] | undefined,
120123
): string[] {
121124
if (value == undefined) {
122125
return [];
@@ -154,7 +157,10 @@ export function formatFlag(
154157
* }
155158
* ```
156159
*/
157-
export function formatFlags(flags: Flags, includes?: string[]): string[] {
160+
export function formatFlags(
161+
flags: Flags,
162+
includes?: readonly string[],
163+
): string[] {
158164
let entries = Object.entries(flags);
159165
if (includes != undefined) {
160166
entries = entries.filter(([k, _]) => includes.includes(k));

argument/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ import { type Flags, parseFlags } from "./flags.ts";
9797
* }
9898
* ```
9999
*/
100-
export function parse(args: string[]): [Opts, Flags, string[]] {
100+
export function parse(args: readonly string[]): [Opts, Flags, string[]] {
101101
const [opts, intermediate] = parseOpts(args);
102102
const [flags, residue] = parseFlags(intermediate);
103103
return [opts, flags, residue];

argument/opts.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const builtinOpts = [
1616
"nobinary",
1717
"bad",
1818
"edit",
19-
];
19+
] as const;
2020

2121
const optPattern = /^\+\+([a-zA-Z0-9-]+)(?:=(.*))?/;
2222

@@ -48,7 +48,7 @@ const optPattern = /^\+\+([a-zA-Z0-9-]+)(?:=(.*))?/;
4848
* }
4949
* ```
5050
*/
51-
export function parseOpts(args: string[]): [Opts, string[]] {
51+
export function parseOpts(args: readonly string[]): [Opts, string[]] {
5252
const opts: Opts = {};
5353
const residue: string[] = [];
5454
for (let i = 0; i < args.length; i++) {
@@ -100,7 +100,10 @@ export function parseOpts(args: string[]): [Opts, string[]] {
100100
* }
101101
* ```
102102
*/
103-
export function validateOpts(opts: Opts, knownAttributes: string[]): void {
103+
export function validateOpts(
104+
opts: Opts,
105+
knownAttributes: readonly string[],
106+
): void {
104107
Object.keys(opts).forEach((v) => {
105108
if (!knownAttributes.includes(v)) {
106109
throw new Error(`Unknown option '++${v}' is specified.`);
@@ -153,7 +156,7 @@ export function formatOpt(key: string, value: string | undefined): string[] {
153156
* }
154157
* ```
155158
*/
156-
export function formatOpts(opts: Opts, includes?: string[]): string[] {
159+
export function formatOpts(opts: Opts, includes?: readonly string[]): string[] {
157160
let entries = Object.entries(opts);
158161
if (includes != undefined) {
159162
entries = entries.filter(([k, _]) => includes.includes(k));

0 commit comments

Comments
 (0)