Skip to content

Commit 6759bee

Browse files
committed
chore: update lint config and fix lint issues
1 parent 9f2c1e6 commit 6759bee

40 files changed

+513
-692
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
node_modules/
12
/test/fixtures
23
dist/

.eslintrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"extends": ["kaisermann/typescript"],
2+
"extends": ["kiwi"],
33
"env": {
44
"node": true,
55
"jest": true
6+
},
7+
"rules": {
8+
"@typescript-eslint/no-explicit-any": "off",
9+
"no-console": "off"
610
}
7-
}
11+
}

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-preprocess",
3-
"version": "3.9.0",
3+
"version": "3.9.1",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -30,8 +30,8 @@
3030
"test": "jest",
3131
"test:watch": "jest --watchAll",
3232
"test:ci": "jest --silent --no-cache",
33-
"lint": "eslint **/*.ts",
34-
"format": "prettier --loglevel silent --write \"src/**/*.ts\" && eslint --fix \"src/**/*.ts\"",
33+
"lint": "eslint {src,test}/**/*.ts",
34+
"format": "prettier --loglevel silent --write \"{src,test}/**/*.ts\" && eslint --fix \"{src,test}/**/*.ts\"",
3535
"postinstall": "echo \"[svelte-preprocess] Don't forget to install the preprocessors packages that will be used: node-sass/sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc...\"",
3636
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md",
3737
"tag": "git tag -a v$npm_package_version -m 'Release v$npm_package_version'",
@@ -67,21 +67,22 @@
6767
"@babel/preset-env": "^7.10.2",
6868
"@types/jest": "^25.2.3",
6969
"@types/node": "^14.0.11",
70+
"@types/node-sass": "^4.11.1",
7071
"@types/stylus": "^0.48.32",
7172
"autoprefixer": "^9.8.0",
7273
"babel-minify": "^0.5.1",
7374
"coffeescript": "^2.5.1",
7475
"conventional-changelog-cli": "^2.0.34",
75-
"eslint-config-kaisermann": "0.2.0",
76-
"eslint": "^7.1.0",
76+
"eslint": "^6.0.0",
77+
"eslint-config-kiwi": "^1.0.2",
7778
"husky": "^4.2.5",
7879
"jest": "^25.0.0",
7980
"less": "^3.11.2",
8081
"lint-staged": "^10.2.9",
8182
"node-sass": "^4.14.1",
83+
"postcss": "^7.0.32",
8284
"postcss-easy-import": "^3.0.0",
8385
"postcss-load-config": "^2.1.0",
84-
"postcss": "^7.0.32",
8586
"prettier": "^2.0.5",
8687
"pug": "^3.0.0",
8788
"sass": "^1.26.8",

src/autoProcess.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type AutoPreprocessOptions = {
4242
markupTagName?: string;
4343
/** @deprecated add transformer config directly to svelte-preprocess options object */
4444
transformers?: Transformers;
45-
aliases?: [string, string][];
45+
aliases?: Array<[string, string]>;
4646
preserve?: string[];
4747
typescript?: TransformerOptions<Options.Typescript>;
4848
scss?: TransformerOptions<Options.Sass>;
@@ -60,7 +60,7 @@ type AutoPreprocessOptions = {
6060
[languageName: string]:
6161
| string
6262
| Promise<string>
63-
| [string, string][]
63+
| Array<[string, string]>
6464
| string[]
6565
| TransformerOptions;
6666
};
@@ -89,7 +89,7 @@ export function autoPreprocess(
8989
`<${markupTagName}([\\s\\S]*?)(?:>([\\s\\S]*)<\\/${markupTagName}>|/>)`,
9090
);
9191

92-
if (aliases && aliases.length) {
92+
if (aliases?.length) {
9393
addLanguageAlias(aliases);
9494
}
9595

@@ -191,8 +191,10 @@ export function autoPreprocess(
191191
.filter(Boolean)
192192
.reduce((acc: Record<string, string | boolean>, attr) => {
193193
const [name, value] = attr.split('=');
194+
194195
// istanbul ignore next
195196
acc[name] = value ? value.replace(/['"]/g, '') : true;
197+
196198
return acc;
197199
}, {});
198200

@@ -276,6 +278,7 @@ export function autoPreprocess(
276278
map,
277279
filename,
278280
});
281+
279282
code = transformed.code;
280283
map = transformed.map;
281284
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { autoPreprocess } from './autoProcess';
22

33
// default auto processor
44
// crazy es6/cjs export mix for backward compatibility
5+
6+
// eslint-disable-next-line no-multi-assign
57
export default exports = module.exports = autoPreprocess;
68

79
// stand-alone processors to be included manually */

src/modules/concat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export function concat(...arrs: any[]): any[] {
33
if (a) {
44
return acc.concat(a);
55
}
6+
67
return acc;
78
}, []);
89
}

src/modules/globalifySelector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function globalifySelector(selector: string) {
1010
if (selectorPart.startsWith(':global')) {
1111
return selectorPart;
1212
}
13+
1314
return `:global(${selectorPart})`;
1415
})
1516
.join(' ');

src/modules/hasPostcssInstalled.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export async function hasPostCssInstalled() {
66
}
77

88
let result = false;
9+
910
try {
1011
await import('postcss');
1112
result = true;

src/modules/language.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const getLanguage = (
3939
throw new Error('src attribute must be string');
4040
}
4141
const parts = basename(attributes.src).split('.');
42+
4243
lang = parts.length > 1 ? parts.pop() : defaultLang;
4344
}
4445

src/modules/parseFile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { readFile, access } from 'fs';
22
import { resolve, dirname } from 'path';
33

44
import { PreprocessorArgs } from '../types';
5-
65
import { getLanguage } from './language';
76

87
export const resolveSrc = (importerFile: string, srcPath: string) =>
@@ -27,12 +26,14 @@ export const parseFile = async (
2726
language: string,
2827
) => {
2928
const dependencies = [];
29+
3030
if (attributes.src) {
3131
// istanbul ignore if
3232
if (typeof attributes.src !== 'string') {
3333
throw new Error('src attribute must be string');
3434
}
3535
let path = attributes.src;
36+
3637
/** Only try to get local files (path starts with ./ or ../) */
3738
if (path.match(/^(https?:)?\/\//) == null) {
3839
path = resolveSrc(filename, path);

src/modules/transformers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import stripIndent from 'strip-indent';
22

33
import { Transformer, TransformerArgs, TransformerOptions } from '../types';
4-
54
import { throwError } from './errors';
65

76
const TRANSFORMERS = {} as {
@@ -10,7 +9,7 @@ const TRANSFORMERS = {} as {
109

1110
export const runTransformer = async (
1211
name: string,
13-
options: TransformerOptions<any>,
12+
options: TransformerOptions,
1413
{ content, map, filename }: TransformerArgs<any>,
1514
): Promise<ReturnType<Transformer<unknown>>> => {
1615
// remove any unnecessary indentation (useful for coffee, pug and sugarss)

src/processors/globalStyle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default (): PreprocessorGroup => {
66
const { default: transformer } = await import(
77
'../transformers/globalStyle'
88
);
9+
910
if (!attributes.global) return { code: content };
1011

1112
return transformer({ content, filename });

src/processors/stylus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default (options: Options.Stylus): PreprocessorGroup => ({
99
svelteFile,
1010
'css',
1111
);
12+
1213
if (lang !== 'stylus') return { code: content };
1314

1415
const transformed = await transformer({ content, filename, options });

src/processors/typescript.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default (options: Options.Typescript): PreprocessorGroup => ({
99
svelteFile,
1010
'javascript',
1111
);
12+
1213
if (lang !== 'typescript') return { code: content };
1314

1415
const transformed = await transformer({ content, filename, options });

src/transformers/babel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const transformer: Transformer<Options.Babel> = async ({
1717
inputSourceMap: map as any,
1818
sourceType: 'module',
1919
// istanbul ignore next
20-
sourceMaps: options.sourceMaps ? true : false,
20+
sourceMaps: !!options.sourceMaps,
2121
filename,
2222
minified: false,
2323
ast: false,

src/transformers/globalRule.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const selectorPattern = /:global(?!\()/;
88
const globalifyRulePlugin = (root: any) => {
99
root.walkRules(selectorPattern, (rule: any) => {
1010
const [beginning, ...rest] = rule.selector.split(selectorPattern);
11+
1112
rule.selector = [beginning, ...rest.map(globalifySelector)]
1213
.map((str) => str.trim())
1314
.join(' ')

src/transformers/postcss.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const process = async (
77
content: string,
88
filename: string,
99
sourceMap: string | object,
10+
// eslint-disable-next-line max-params
1011
) => {
1112
const { css, map, messages } = await postcss(plugins).process(content, {
1213
from: filename,
@@ -60,6 +61,7 @@ const transformer: Transformer<Options.Postcss> = async ({
6061
} else {
6162
console.error(e);
6263
}
64+
6365
return { code: content, map, dependencies: [] as any[] };
6466
}
6567

src/transformers/pug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const transformer: Transformer<Options.Pug> = async ({
6161
...options,
6262
// @types/pug compile() returned value doesn't have `dependencies` prop
6363
}) as pug.compileTemplate & { dependencies?: string[] };
64+
6465
return {
6566
code: compiled(),
6667
dependencies: compiled.dependencies ?? null,

src/transformers/scss.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const transformer: Transformer<Options.Sass> = async ({
2929

3030
if (implementation == null) {
3131
const mod = await importAny('node-sass', 'sass');
32+
33+
// eslint-disable-next-line no-multi-assign
3234
implementation = sass = mod.default;
3335
}
3436

src/transformers/typescript.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function formatDiagnostics(
2525
createFormatDiagnosticsHost(basePath),
2626
);
2727
}
28+
2829
return ts.formatDiagnostic(
2930
diagnostics,
3031
createFormatDiagnosticsHost(basePath),
@@ -34,25 +35,31 @@ function formatDiagnostics(
3435
function getFilenameExtension(filename: string) {
3536
filename = basename(filename);
3637
const lastDotIndex = filename.lastIndexOf('.');
38+
3739
if (lastDotIndex <= 0) return '';
40+
3841
return filename.substr(lastDotIndex + 1);
3942
}
4043

4144
function isSvelteFile(filename: string) {
4245
const importExtension = getFilenameExtension(filename);
46+
4347
return importExtension === 'svelte' || importExtension === 'html';
4448
}
4549

4650
const IMPORTEE_PATTERN = /['"](.*?)['"]/;
51+
4752
function isValidSvelteImportDiagnostic(filename: string, diagnostic: any) {
4853
// TS2307: 'cannot find module'
4954
if (diagnostic.code !== 2307) return true;
5055

5156
const importeeMatch = diagnostic.messageText.match(IMPORTEE_PATTERN);
57+
5258
// istanbul ignore if
5359
if (!importeeMatch) return true;
5460

5561
let [, importeePath] = importeeMatch;
62+
5663
/** if we're not dealing with a relative path, assume the file exists */
5764
if (importeePath[0] !== '.') return false;
5865

@@ -74,6 +81,7 @@ const importTransformer: ts.TransformerFactory<ts.SourceFile> = (context) => {
7481
node.moduleSpecifier,
7582
);
7683
}
84+
7785
return ts.visitEachChild(node, (child) => visit(child), context);
7886
};
7987

@@ -85,6 +93,7 @@ const TS_TRANSFORMERS = {
8593
};
8694

8795
const TS2552_REGEX = /Cannot find name '\$([a-zA-Z0-9_]+)'. Did you mean '([a-zA-Z0-9_]+)'\?/i;
96+
8897
function isValidSvelteReactiveValueDiagnostic(
8998
filename: string,
9099
diagnostic: any,
@@ -130,6 +139,7 @@ function compileFileFromMemory(
130139
languageVersion,
131140
onError,
132141
shouldCreateNewSourceFile,
142+
// eslint-disable-next-line max-params
133143
) =>
134144
isDummyFile(fileName)
135145
? ts.createSourceFile(dummyFileName, code, languageVersion)
@@ -210,6 +220,7 @@ const transformer: Transformer<Options.Typescript> = ({
210220
tsconfigFile,
211221
ts.sys.readFile,
212222
);
223+
213224
if (error) {
214225
throw new Error(formatDiagnostics(error, basePath));
215226
}
@@ -224,6 +235,7 @@ const transformer: Transformer<Options.Typescript> = ({
224235
errors,
225236
options: convertedCompilerOptions,
226237
} = ts.convertCompilerOptionsFromJson(compilerOptionsJSON, basePath);
238+
227239
if (errors.length) {
228240
throw new Error(formatDiagnostics(errors, basePath));
229241
}
@@ -242,13 +254,16 @@ const transformer: Transformer<Options.Typescript> = ({
242254
);
243255
}
244256

245-
let code, map, diagnostics;
257+
let code;
258+
let map;
259+
let diagnostics;
260+
246261
if (options.transpileOnly || compilerOptions.transpileOnly) {
247262
({ outputText: code, sourceMapText: map, diagnostics } = ts.transpileModule(
248263
content,
249264
{
250265
fileName: filename,
251-
compilerOptions: compilerOptions,
266+
compilerOptions,
252267
reportDiagnostics: options.reportDiagnostics !== false,
253268
transformers: TS_TRANSFORMERS,
254269
},
@@ -263,6 +278,7 @@ const transformer: Transformer<Options.Typescript> = ({
263278
if (diagnostics.length > 0) {
264279
// could this be handled elsewhere?
265280
const formattedDiagnostics = formatDiagnostics(diagnostics, basePath);
281+
266282
console.log(formattedDiagnostics);
267283
}
268284

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface TransformerArgs<T> {
2121
content: string;
2222
filename: string;
2323
map?: string | object;
24-
dianostics?: Array<unknown>;
24+
dianostics?: unknown[];
2525
options?: T;
2626
}
2727

0 commit comments

Comments
 (0)