Skip to content

Commit a7f7f46

Browse files
committed
Fix linting
1 parent fd68e9d commit a7f7f46

19 files changed

+147
-142
lines changed

.eslintrc.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

.eslintrc.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"env": {
3+
"es2021": true,
4+
"node": true,
5+
"mocha": true
6+
},
7+
"extends": [
8+
"eslint:recommended", "google"
9+
],
10+
"parserOptions": {
11+
"ecmaVersion": 2021, // ecma2021
12+
"sourceType": "module"
13+
},
14+
"rules": {
15+
"require-jsdoc": "off",
16+
"no-constant-condition": ["error", {"checkLoops": false}], /* while(true) is a common and useful idiom */
17+
"no-inner-declarations": "off",
18+
19+
/* Formatting annoyances: */
20+
"max-len": ["error", {"code": 120, "ignoreComments": true, "ignoreTrailingComments": true}],
21+
"no-trailing-spaces": ["error", {"skipBlankLines": true, "ignoreComments": true}],
22+
"no-multiple-empty-lines": "off",
23+
"padded-blocks": "off",
24+
"one-var": "off",
25+
"no-multi-spaces": "off",
26+
"computed-property-spacing": "off",
27+
28+
"new-cap": "off", /* Just causes problems with callbacks */
29+
30+
"valid-jsdoc": "off", /* Eslint can't parse closure/typescript complex types */
31+
32+
/* Make into warnings - these are common when prototyping code: */
33+
"no-unused-vars": "warn",
34+
"prefer-const": "warn"
35+
}
36+
}

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ coverage/
1818
# actually *lowers* npm's quality score :(
1919

2020
# Dev env
21-
# .eslintrc.js
21+
# .eslintrc.json
2222
# jsconfig.json
2323
# tsconfig.json
2424

build.binaries.config.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
win64: ['bin/glslangValidator.exe'],
1717
ubuntu64: ['bin/glslangValidator'],
1818
macos64: ['bin/glslangValidator'],
19-
}
19+
},
2020
},
2121
{
2222
name: 'spirv-opt',
@@ -29,15 +29,15 @@ export default {
2929
macos64: 'https://storage.googleapis.com/spirv-tools/badges/build_link_macos_clang_release.html',
3030
},
3131
matchers: {
32-
win64: /windows.*\/([^-\/]+)-[^\/]+\/([^\/]+)$/i,
33-
ubuntu64: /linux.*\/([^-\/]+)-[^\/]+\/([^\/]+)$/i,
34-
macos64: /macos.*\/([^-\/]+)-[^\/]+\/([^\/]+)$/i,
32+
win64: /windows.*\/([^-/]+)-[^/]+\/([^/]+)$/i,
33+
ubuntu64: /linux.*\/([^-/]+)-[^/]+\/([^/]+)$/i,
34+
macos64: /macos.*\/([^-/]+)-[^/]+\/([^/]+)$/i,
3535
},
3636
filelist: {
3737
win64: ['install/bin/spirv-opt.exe'],
3838
ubuntu64: ['install/bin/spirv-opt'],
3939
macos64: ['install/bin/spirv-opt'],
40-
}
40+
},
4141
},
4242
{
4343
name: 'spirv-cross',
@@ -62,22 +62,22 @@ export default {
6262
name: 'glslangValidator LICENSE',
6363
url: 'https://raw.githubusercontent.com/KhronosGroup/glslang/master/LICENSE.txt',
6464
fileList: [
65-
'glslangValidator-LICENSE'
66-
]
65+
'glslangValidator-LICENSE',
66+
],
6767
},
6868
{
6969
name: 'spirv-opt LICENSE',
7070
url: 'https://raw.githubusercontent.com/KhronosGroup/SPIRV-Tools/master/LICENSE',
7171
fileList: [
72-
'spirv-opt-LICENSE'
73-
]
72+
'spirv-opt-LICENSE',
73+
],
7474
},
7575
{
7676
name: 'spirv-cross LICENSE',
7777
url: 'https://raw.githubusercontent.com/KhronosGroup/SPIRV-Cross/master/LICENSE',
7878
fileList: [
79-
'spirv-cross-LICENSE'
80-
]
81-
}
79+
'spirv-cross-LICENSE',
80+
],
81+
},
8282
],
8383
};

build.binaries.mjs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const runBuildFetchStep = async (buildStep, targetDir) => {
9898
async function jsonRequest(url) {
9999
try {
100100
const response = await fetch(url, {
101-
method: 'GET'
101+
method: 'GET',
102102
});
103103
if (!response.ok) throw new Error(`Bad response code: ${response.status}`);
104104
return response.json();
@@ -119,9 +119,9 @@ async function fetchMatchingGithubRelease(repo, releaseMatchers) {
119119
}
120120
let foundReleaseInfo;
121121
for (const releaseInfo of releaseInfos) {
122-
if (releaseInfo.draft // Skip draft releases
123-
|| !releaseInfo.html_url || !releaseInfo.created_at || !releaseInfo.target_commitish // Missing info
124-
|| !releaseInfo.assets || !releaseInfo.assets.length // No assets
122+
if (releaseInfo.draft || // Skip draft releases
123+
!releaseInfo.html_url || !releaseInfo.created_at || !releaseInfo.target_commitish || // Missing info
124+
!releaseInfo.assets || !releaseInfo.assets.length // No assets
125125
) continue;
126126

127127
const matchAssets = new Set(releaseInfo.assets);
@@ -146,9 +146,10 @@ async function fetchMatchingGithubRelease(repo, releaseMatchers) {
146146
url: releaseInfo.html_url,
147147
hash: releaseInfo.target_commitish,
148148
date: releaseInfo.created_at,
149-
tag: new Date(releaseInfo.created_at).toISOString().split('T')[0] + '-' + releaseInfo.target_commitish.slice(0, 7),
149+
tag: new Date(releaseInfo.created_at).toISOString().split('T')[0] +
150+
'-' + releaseInfo.target_commitish.slice(0, 7),
150151
platforms: matchedPlats,
151-
}
152+
};
152153
break;
153154
} else {
154155
// We could continue searching down releases, but better to throw an error in case
@@ -170,7 +171,7 @@ async function fetchSpirvToolsCIPage(url) {
170171
let resultHTML;
171172
try {
172173
const response = await fetch(url, {
173-
method: 'GET'
174+
method: 'GET',
174175
});
175176
if (!response.ok) throw new Error(`Bad response code: ${response.status}`);
176177
resultHTML = await response.text();
@@ -221,7 +222,9 @@ async function fetchMatchingSpirvToolsCI(urls, releaseMatchers) {
221222
if (!thisPlat) throw new Error(`Couldn't identify this platform's tag`);
222223

223224
const buildConfig = /** @type {BuildConfig} */((await import('./build.binaries.config.mjs')).default);
224-
if (!buildConfig || !buildConfig.targets || !buildConfig.sources || !buildConfig.include) throw new Error(`Bad build config`);
225+
if (!buildConfig || !buildConfig.targets || !buildConfig.sources || !buildConfig.include) {
226+
throw new Error(`Bad build config`);
227+
}
225228

226229
rmFile(buildInfoFile);
227230
rmDir(buildFolder);
@@ -234,16 +237,17 @@ async function fetchMatchingSpirvToolsCI(urls, releaseMatchers) {
234237
switch (source.type) {
235238
case 'githubrelease':
236239
sourceResult = await fetchMatchingGithubRelease(source.repo, source.matchers);
237-
break;
240+
break;
238241
case 'spirvtoolsci':
239242
sourceResult = await fetchMatchingSpirvToolsCI(source.urls, source.matchers);
240-
break;
243+
break;
241244
default: throw new Error(`build config error: Unknown type '${source.type}' for source '${source.name}'`);
242245
}
243246
for (const target of buildConfig.targets) {
244247
if (!sourceResult.platforms[target]) throw new Error(`source '${source.name}' missing target '${target}'`);
245248
}
246-
sources.push({...sourceResult, name: source.name, filelist: source.filelist, verargs: source.verargs, vermatch: source.vermatch});
249+
sources.push({...sourceResult, name: source.name, filelist: source.filelist,
250+
verargs: source.verargs, vermatch: source.vermatch});
247251
}
248252

249253
const includeFiles = [];
@@ -265,7 +269,7 @@ async function fetchMatchingSpirvToolsCI(urls, releaseMatchers) {
265269

266270
for (const source of sources) {
267271
const url = source.platforms[target].url;
268-
const extMatch = url.match(/\.(tar\.gz|tgz|zip)$/i) || ['',''];
272+
const extMatch = url.match(/\.(tar\.gz|tgz|zip)$/i) || ['', ''];
269273
let action;
270274
switch (extMatch[1].toLowerCase()) {
271275
case 'tar.gz': case 'tgz': action = 'untargz'; break;

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"chai": "^4.3.4",
6666
"chai-as-promised": "^7.1.1",
6767
"del": "^6.0.0",
68-
"eslint": "^7.22.0",
68+
"eslint": "^7.25.0",
6969
"eslint-config-google": "^0.14.0",
7070
"he": "^1.2.0",
7171
"mocha": "^8.3.2",

src/index.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createFilter} from '@rollup/pluginutils';
2-
import { glslProcessSource } from './lib/glslProcess.js';
2+
import {glslProcessSource} from './lib/glslProcess.js';
33
import {dirname} from 'path';
44
import * as fsSync from 'fs';
55

@@ -8,28 +8,28 @@ import * as fsSync from 'fs';
88
* @typedef {{[P in GLSLStageName]: string[]}} GLSLStageDefs */
99
/** @type {GLSLStageDefs} */
1010
const stageDefs = {
11-
'vert': [ '.vs', '.vert', '.vs.glsl', '.vert.glsl' ],
12-
'frag': [ '.fs', '.frag', '.fs.glsl', '.frag.glsl' ],
11+
'vert': ['.vs', '.vert', '.vs.glsl', '.vert.glsl'],
12+
'frag': ['.fs', '.frag', '.fs.glsl', '.frag.glsl'],
1313
// The following are untested:
14-
'geom': [ '.geom', '.geom.glsl' ],
15-
'comp': [ '.comp', '.comp.glsl' ],
16-
'tesc': [ '.tesc', '.tesc.glsl' ],
17-
'tese': [ '.tese', '.tese.glsl' ],
14+
'geom': ['.geom', '.geom.glsl'],
15+
'comp': ['.comp', '.comp.glsl'],
16+
'tesc': ['.tesc', '.tesc.glsl'],
17+
'tese': ['.tese', '.tese.glsl'],
1818
};
1919

2020
const extsIncludeDefault = [...Object.values(stageDefs).flatMap(
21-
(exts) => exts.map((ext) => `**/*${ext}`)),
22-
'**/*.glsl',
21+
(exts) => exts.map((ext) => `**/*${ext}`)),
22+
'**/*.glsl',
2323
// Additionally include all *.glsl by default so we throw an error
2424
// if the user includes a file extension without a stage
2525
];
2626

2727
/** @type {[GLSLStageName, RegExp][]} */
2828
const stageRegexes = (
2929
/** @type {[GLSLStageName, string[]][]} */(Object.entries(stageDefs))
30-
.map(([st, exts]) => [st,
31-
new RegExp(`(?:${exts.map(ext => ext.replace('.', '\\.')).join('|')})$`, 'i')
32-
]));
30+
.map(([st, exts]) => [st,
31+
new RegExp(`(?:${exts.map((ext) => ext.replace('.', '\\.')).join('|')})$`, 'i'),
32+
]));
3333

3434
function generateCode(source) {
3535
return `export default ${JSON.stringify(source)}; // eslint-disable-line`;
@@ -83,7 +83,9 @@ export default function glslOptimize(userOptions = {}) {
8383
if (glslify && glslify.compile && typeof glslify.compile === 'function') {
8484
glslifyCompile = glslify.compile;
8585
}
86-
} catch {}
86+
} catch {
87+
// do nothing
88+
}
8789
}
8890
return options;
8991
},
@@ -107,22 +109,22 @@ export default function glslOptimize(userOptions = {}) {
107109
/** @type {GLSLStageName} */
108110
const stage = stageRegexes.find(([, regex]) => id.match(regex))?.[0];
109111
if (!stage) {
110-
this.error({ message: `File '${id}' : extension did not match a shader stage.` });
112+
this.error({message: `File '${id}' : extension did not match a shader stage.`});
111113
}
112114

113115
if (pluginOptions.glslify) {
114116
if (!glslifyCompile) {
115-
this.error({ message: `glslify could not be found. Install it with npm i -D glslify`});
117+
this.error({message: `glslify could not be found. Install it with npm i -D glslify`});
116118
}
117119
/** @type {GlslifyOptions} */
118120
const glslifyOptions = {
119121
basedir: dirname(id),
120122
...pluginOptions.glslifyOptions,
121-
}
123+
};
122124
try {
123125
source = glslifyCompile(source, glslifyOptions);
124126
} catch (err) {
125-
this.error({ message: `Error processing GLSL source with glslify:\n${err.message}` });
127+
this.error({message: `Error processing GLSL source with glslify:\n${err.message}`});
126128
}
127129
}
128130

@@ -131,7 +133,7 @@ export default function glslOptimize(userOptions = {}) {
131133
result.code = generateCode(result.code);
132134
return result;
133135
} catch (err) {
134-
this.error({ message: `Error processing GLSL source:\n${err.message}` });
136+
this.error({message: `Error processing GLSL source:\n${err.message}`});
135137
}
136138
},
137139
};

0 commit comments

Comments
 (0)