(source: string)
| 919 | * `ignorefile.ReadAll` followed by `patternmatcher.New`. |
| 920 | */ |
| 921 | const parseDockerignore = (source: string): Array<DockerPattern> | DockerError => { |
| 922 | const patterns: Array<DockerPattern> = [] |
| 923 | const lines = source.split("\n") |
| 924 | for (let index = 0; index < lines.length; index++) { |
| 925 | let line = lines[index] |
| 926 | if (line.endsWith("\r")) { |
| 927 | line = line.slice(0, -1) |
| 928 | } |
| 929 | if (index === 0 && line.startsWith("")) { |
| 930 | line = line.slice(1) |
| 931 | } |
| 932 | if (line.startsWith("#")) { |
| 933 | continue |
| 934 | } |
| 935 | const trimmed = goTrim(line) |
| 936 | if (trimmed === "") { |
| 937 | continue |
| 938 | } |
| 939 | let exclusion = trimmed.startsWith("!") |
| 940 | let pattern = exclusion ? goTrim(trimmed.slice(1)) : trimmed |
| 941 | if (pattern !== "") { |
| 942 | pattern = clean(pattern) |
| 943 | if (pattern.length > 1 && pattern.startsWith("/")) { |
| 944 | pattern = pattern.slice(1) |
| 945 | } |
| 946 | } |
| 947 | if (exclusion) { |
| 948 | pattern = `!${pattern}` |
| 949 | } |
| 950 | // `New` trims and cleans the result again before reading a leading `!`, |
| 951 | // so `!/` is a bare `!`, `/ x` is `x` and `/!x` is an exception |
| 952 | pattern = goTrim(pattern) |
| 953 | if (pattern === "") { |
| 954 | continue |
| 955 | } |
| 956 | pattern = clean(pattern) |
| 957 | exclusion = pattern.startsWith("!") |
| 958 | if (exclusion) { |
| 959 | if (pattern.length === 1) { |
| 960 | return { line: index + 1, pattern: trimmed, message: `illegal exclusion pattern: "!"` } |
| 961 | } |
| 962 | pattern = pattern.slice(1) |
| 963 | } |
| 964 | const match = compileDocker(pattern) |
| 965 | if (typeof match === "string") { |
| 966 | return { line: index + 1, pattern: trimmed, message: match } |
| 967 | } |
| 968 | patterns.push({ exclusion, matcher: dockerMatcher(pattern, match) }) |
| 969 | } |
| 970 | return patterns |
| 971 | } |
| 972 | |
| 973 | const wildcardChars = /[*[\]?^\\]/ |
| 974 |
no test coverage detected