Skip to content

Commit f6ef334

Browse files
committed
chore: update linter, formatter and fix linting issues
1 parent 741d314 commit f6ef334

25 files changed

+119
-130
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
"@babel/preset-env": "^7.10.2",
7878
"@commitlint/cli": "^11.0.0",
7979
"@commitlint/config-conventional": "^11.0.0",
80-
"@kiwi/eslint-config": "^1.16.6",
81-
"@kiwi/prettier-config": "^1.16.6",
80+
"@kiwi/eslint-config": "^1.18.1",
81+
"@kiwi/prettier-config": "^1.18.1",
8282
"@types/jest": "^27.0.2",
8383
"@types/node": "^14.0.11",
8484
"@types/node-sass": "^4.11.1",

src/autoProcess.ts

+50-54
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
import type {
2-
AutoPreprocessGroup,
3-
AutoPreprocessOptions,
4-
PreprocessorGroup,
5-
Preprocessor,
6-
Processed,
7-
TransformerArgs,
8-
TransformerOptions,
9-
Transformers,
10-
} from './types';
111
import { hasDepInstalled, concat, setProp } from './modules/utils';
122
import { getTagInfo } from './modules/tagInfo';
133
import {
@@ -21,6 +11,17 @@ import {
2111
import { prepareContent } from './modules/prepareContent';
2212
import { transformMarkup } from './modules/markup';
2313

14+
import type {
15+
AutoPreprocessGroup,
16+
AutoPreprocessOptions,
17+
PreprocessorGroup,
18+
Preprocessor,
19+
Processed,
20+
TransformerArgs,
21+
TransformerOptions,
22+
Transformers,
23+
} from './types';
24+
2425
export const transform = async (
2526
name: string | null | undefined,
2627
options: TransformerOptions,
@@ -122,59 +123,54 @@ export function sveltePreprocess(
122123
return resolveLanguageArgs(lang, alias);
123124
}
124125

125-
const getTransformerTo = (
126-
type: 'markup' | 'script' | 'style',
127-
targetLanguage: string,
128-
): Preprocessor => async (svelteFile) => {
129-
let {
130-
content,
131-
markup,
132-
filename,
133-
lang,
134-
alias,
135-
dependencies,
136-
attributes,
137-
} = await getTagInfo(svelteFile);
126+
const getTransformerTo =
127+
(
128+
type: 'markup' | 'script' | 'style',
129+
targetLanguage: string,
130+
): Preprocessor =>
131+
async (svelteFile) => {
132+
let { content, markup, filename, lang, alias, dependencies, attributes } =
133+
await getTagInfo(svelteFile);
134+
135+
if (lang == null || alias == null) {
136+
alias = defaultLanguages[type];
137+
lang = getLanguageFromAlias(alias);
138+
}
138139

139-
if (lang == null || alias == null) {
140-
alias = defaultLanguages[type];
141-
lang = getLanguageFromAlias(alias);
142-
}
140+
if ((lang && preserve.includes(lang)) || preserve.includes(alias)) {
141+
return { code: content };
142+
}
143143

144-
if ((lang && preserve.includes(lang)) || preserve.includes(alias)) {
145-
return { code: content };
146-
}
144+
const transformerOptions = getTransformerOptions(lang, alias);
147145

148-
const transformerOptions = getTransformerOptions(lang, alias);
146+
content = prepareContent({
147+
options: transformerOptions,
148+
content,
149+
});
149150

150-
content = prepareContent({
151-
options: transformerOptions,
152-
content,
153-
});
151+
if (lang === targetLanguage) {
152+
// has override method for alias
153+
// example: sugarss override should work apart from postcss
154+
if (typeof transformerOptions === 'function' && alias !== lang) {
155+
return transformerOptions({ content, filename, attributes });
156+
}
154157

155-
if (lang === targetLanguage) {
156-
// has override method for alias
157-
// example: sugarss override should work apart from postcss
158-
if (typeof transformerOptions === 'function' && alias !== lang) {
159-
return transformerOptions({ content, filename, attributes });
158+
// otherwise, we're done here
159+
return { code: content, dependencies };
160160
}
161161

162-
// otherwise, we're done here
163-
return { code: content, dependencies };
164-
}
165-
166-
const transformed = await transform(lang, transformerOptions, {
167-
content,
168-
markup,
169-
filename,
170-
attributes,
171-
});
162+
const transformed = await transform(lang, transformerOptions, {
163+
content,
164+
markup,
165+
filename,
166+
attributes,
167+
});
172168

173-
return {
174-
...transformed,
175-
dependencies: concat(dependencies, transformed.dependencies),
169+
return {
170+
...transformed,
171+
dependencies: concat(dependencies, transformed.dependencies),
172+
};
176173
};
177-
};
178174

179175
const scriptTransformer = getTransformerTo('script', 'javascript');
180176
const cssTransformer = getTransformerTo('style', 'css');

src/modules/language.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { basename } from 'path';
22

3-
import type { PreprocessorArgs } from '../types';
43
import { isValidLocalPath } from './utils';
54

5+
import type { PreprocessorArgs } from '../types';
6+
67
// todo: remove on v5
78
let hasLoggedDeprecatedLangTypescriptWarning = false;
89
let hasLoggedDeprecatedTypeWarning = false;

src/modules/tagInfo.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import { readFile, access } from 'fs';
33
import { resolve, dirname } from 'path';
44

5-
import type { PreprocessorArgs } from '../types';
65
import { getLanguage } from './language';
76
import { isValidLocalPath } from './utils';
87

8+
import type { PreprocessorArgs } from '../types';
9+
910
const resolveSrc = (importerFile: string, srcPath: string) =>
1011
resolve(dirname(importerFile), srcPath);
1112

src/processors/babel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type { PreprocessorGroup, Options } from '../types';
21
import { concat } from '../modules/utils';
32
import { getTagInfo } from '../modules/tagInfo';
43
import { prepareContent } from '../modules/prepareContent';
54

5+
import type { PreprocessorGroup, Options } from '../types';
6+
67
export default (options?: Options.Babel): PreprocessorGroup => ({
78
async script(svelteFile) {
89
const { transformer } = await import('../transformers/babel');

src/processors/coffeescript.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import type { PreprocessorGroup, Options } from '../types';
21
import { getTagInfo } from '../modules/tagInfo';
32
import { concat } from '../modules/utils';
43
import { prepareContent } from '../modules/prepareContent';
54

5+
import type { PreprocessorGroup, Options } from '../types';
6+
67
export default (options?: Options.Coffeescript): PreprocessorGroup => ({
78
async script(svelteFile) {
89
const { transformer } = await import('../transformers/coffeescript');
910

10-
let {
11-
content,
12-
filename,
13-
attributes,
14-
lang,
15-
dependencies,
16-
} = await getTagInfo(svelteFile);
11+
let { content, filename, attributes, lang, dependencies } =
12+
await getTagInfo(svelteFile);
1713

1814
if (lang !== 'coffeescript') {
1915
return { code: content };

src/processors/less.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import type { PreprocessorGroup, Options } from '../types';
21
import { getTagInfo } from '../modules/tagInfo';
32
import { concat } from '../modules/utils';
43
import { prepareContent } from '../modules/prepareContent';
54

5+
import type { PreprocessorGroup, Options } from '../types';
6+
67
export default (options?: Options.Less): PreprocessorGroup => ({
78
async style(svelteFile) {
89
const { transformer } = await import('../transformers/less');
9-
let {
10-
content,
11-
filename,
12-
attributes,
13-
lang,
14-
dependencies,
15-
} = await getTagInfo(svelteFile);
10+
let { content, filename, attributes, lang, dependencies } =
11+
await getTagInfo(svelteFile);
1612

1713
if (lang !== 'less') {
1814
return { code: content };

src/processors/postcss.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type { PreprocessorGroup, Options } from '../types';
21
import { getTagInfo } from '../modules/tagInfo';
32
import { concat } from '../modules/utils';
43
import { prepareContent } from '../modules/prepareContent';
54

5+
import type { PreprocessorGroup, Options } from '../types';
6+
67
/** Adapted from https://github.com/TehShrike/svelte-preprocess-postcss */
78
export default (options?: Options.Postcss): PreprocessorGroup => ({
89
async style(svelteFile) {

src/processors/pug.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { Options, PreprocessorGroup } from '../types/index';
21
import { prepareContent } from '../modules/prepareContent';
32
import { transformMarkup } from '../modules/markup';
43

4+
import type { Options, PreprocessorGroup } from '../types/index';
5+
56
export default (options?: Options.Pug): PreprocessorGroup => ({
67
async markup({ content, filename }) {
78
const { transformer } = await import('../transformers/pug');

src/processors/scss.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
import type { PreprocessorGroup, Options } from '../types';
21
import { getTagInfo } from '../modules/tagInfo';
32
import { concat } from '../modules/utils';
43
import { prepareContent } from '../modules/prepareContent';
54

5+
import type { PreprocessorGroup, Options } from '../types';
6+
67
export default (options?: Options.Sass): PreprocessorGroup => ({
78
async style(svelteFile) {
89
const { transformer } = await import('../transformers/scss');
9-
let {
10-
content,
11-
filename,
12-
attributes,
13-
lang,
14-
alias,
15-
dependencies,
16-
} = await getTagInfo(svelteFile);
10+
let { content, filename, attributes, lang, alias, dependencies } =
11+
await getTagInfo(svelteFile);
1712

1813
if (alias === 'sass') {
1914
options = {

src/processors/stylus.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import type { Options, PreprocessorGroup } from '../types';
21
import { getTagInfo } from '../modules/tagInfo';
32
import { concat } from '../modules/utils';
43
import { prepareContent } from '../modules/prepareContent';
54

5+
import type { Options, PreprocessorGroup } from '../types';
6+
67
export default (options?: Options.Stylus): PreprocessorGroup => ({
78
async style(svelteFile) {
89
const { transformer } = await import('../transformers/stylus');
9-
let {
10-
content,
11-
filename,
12-
attributes,
13-
lang,
14-
dependencies,
15-
} = await getTagInfo(svelteFile);
10+
let { content, filename, attributes, lang, dependencies } =
11+
await getTagInfo(svelteFile);
1612

1713
if (lang !== 'stylus') {
1814
return { code: content };

src/processors/typescript.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
import type { Options, PreprocessorGroup } from '../types';
21
import { getTagInfo } from '../modules/tagInfo';
32
import { concat } from '../modules/utils';
43
import { prepareContent } from '../modules/prepareContent';
54

5+
import type { Options, PreprocessorGroup } from '../types';
6+
67
export default (options?: Options.Typescript): PreprocessorGroup => ({
78
async script(svelteFile) {
89
const { transformer } = await import('../transformers/typescript');
9-
let {
10-
content,
11-
markup,
12-
filename,
13-
attributes,
14-
lang,
15-
dependencies,
16-
} = await getTagInfo(svelteFile);
10+
let { content, markup, filename, attributes, lang, dependencies } =
11+
await getTagInfo(svelteFile);
1712

1813
if (lang !== 'typescript') {
1914
return { code: content };

src/transformers/babel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { TransformOptions } from '@babel/core';
21
import { transformAsync } from '@babel/core';
32

3+
import type { TransformOptions } from '@babel/core';
44
import type { Transformer, Options } from '../types';
55

66
const transformer: Transformer<Options.Babel> = async ({

src/transformers/globalStyle.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import postcss from 'postcss';
2-
import type * as pcss from 'postcss';
32

4-
import type { Transformer, Options } from '../types';
53
import { globalifySelector } from '../modules/globalifySelector';
64

5+
import type * as pcss from 'postcss';
6+
import type { Transformer, Options } from '../types';
7+
78
const selectorPattern = /:global(?!\()/;
89

910
const globalifyRulePlugin = (root: pcss.Root) => {

src/transformers/less.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import less from 'less';
22

33
import { getIncludePaths } from '../modules/utils';
4+
45
import type { Transformer, Options } from '../types';
56

67
const transformer: Transformer<Options.Less> = async ({

src/transformers/scss.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { readFileSync } from 'fs';
22
import { join, isAbsolute } from 'path';
33

4-
import type { Importer, Result } from 'sass';
5-
64
import { getIncludePaths, importAny, findUp } from '../modules/utils';
5+
6+
import type { Importer, Result } from 'sass';
77
import type { Transformer, Processed, Options } from '../types';
88

99
let sass: Options.Sass['implementation'];

src/transformers/stylus.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
import stylus from 'stylus';
44

55
import { getIncludePaths } from '../modules/utils';
6+
67
import type { Transformer, Options } from '../types';
78

89
const transformer: Transformer<Options.Stylus> = ({

src/transformers/typescript.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import { dirname, isAbsolute, join, resolve } from 'path';
22

33
import ts from 'typescript';
44
import { compile } from 'svelte/compiler';
5-
import pkg from 'svelte/package.json';
65
import MagicString from 'magic-string';
76
import sorcery from 'sorcery';
87

98
import { throwTypescriptError } from '../modules/errors';
109
import { createTagRegex, parseAttributes, stripTags } from '../modules/markup';
11-
import type { Transformer, Options, TransformerArgs } from '../types';
1210
import { JAVASCRIPT_RESERVED_KEYWORD_SET } from '../modules/utils';
1311

12+
import pkg from 'svelte/package.json';
13+
14+
import type { Transformer, Options, TransformerArgs } from '../types';
15+
1416
type CompilerOptions = ts.CompilerOptions;
1517

1618
type SourceMapChain = {

src/types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import * as Options from './options';
2+
13
import type {
24
Processed as SvelteProcessed,
35
Preprocessor,
46
PreprocessorGroup,
57
} from 'svelte/types/compiler/preprocess';
68

7-
import * as Options from './options';
8-
99
export { Options };
1010

1111
export {

0 commit comments

Comments
 (0)