Skip to content

Commit d4d5734

Browse files
committed
Fix lint issue
1 parent 5fac646 commit d4d5734

19 files changed

+112
-44
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
node_modules/
12
/test/fixtures
23
dist/

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"jest": true
66
},
77
"rules": {
8-
"@typescript-eslint/no-explicit-any": "off"
8+
"@typescript-eslint/no-explicit-any": "off",
9+
"no-console": "off"
910
}
1011
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -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'",

src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { autoPreprocess } from './autoProcess';
22

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

99
// stand-alone processors to be included manually */
1010
export { default as pug } from './processors/pug';

src/transformers/postcss.ts

+1
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,

src/transformers/scss.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const transformer: Transformer<Options.Sass> = async ({
3030
if (implementation == null) {
3131
const mod = await importAny('node-sass', 'sass');
3232

33+
// eslint-disable-next-line no-multi-assign
3334
implementation = sass = mod.default;
3435
}
3536

test/autoProcess/externalFiles.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ describe('external files', () => {
5151
'./some-not-local-file.js',
5252
];
5353

54-
EXTERNALJS.forEach(url => {
54+
EXTERNALJS.forEach((url) => {
5555
it(`should not attempt to locally resolve ${url}`, async () => {
5656
const input = `<div></div><script src="${url}"></script>`;
5757

5858
const preprocessed = await preprocess(input, getAutoPreprocess());
59+
5960
expect(preprocessed.toString()).toContain(input);
60-
expect(preprocessed.dependencies.length).toBe(0);
61+
expect(preprocessed.dependencies).toHaveLength(0);
6162
});
6263
});
6364
});

test/autoProcess/markup.test.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,40 @@ import getAutoPreprocess from '../../src';
22
import { preprocess, getFixtureContent, doesCompileThrow } from '../utils';
33

44
const EXPECTED_MARKUP = getFixtureContent('template.html');
5-
const MARKUP_LANGS: [string, string][] = [['pug', 'pug']];
5+
const MARKUP_LANGS: Array<[string, string]> = [['pug', 'pug']];
66

7-
it('should transform HTML between <template></template>', async () => {
7+
test('should transform HTML between <template></template>', async () => {
88
const input = `<script></script><template><div>Hey</div></template><style></style>`;
99
const preprocessed = await preprocess(input, getAutoPreprocess());
10+
1011
expect(preprocessed.toString()).toBe(
1112
`<script></script>${EXPECTED_MARKUP}<style></style>`,
1213
);
1314
});
1415

15-
it('should transform HTML between custom tag <markup></markup>', async () => {
16+
test('should transform HTML between custom tag <markup></markup>', async () => {
1617
const input = `<script></script><markup><div>Hey</div></markup><style></style>`;
1718
const preprocessed = await preprocess(
1819
input,
1920
getAutoPreprocess({ markupTagName: 'markup' }),
2021
);
22+
2123
expect(preprocessed.toString()).toBe(
2224
`<script></script>${EXPECTED_MARKUP}<style></style>`,
2325
);
2426
});
2527

26-
it('should transform a custom language between <template lang="..."></template>', async () => {
28+
test('should transform a custom language between <template lang="..."></template>', async () => {
2729
const input = `<script></script><template lang="test"><div>Hey</div></template><style></style>`;
2830
const preprocessed = await preprocess(
2931
input,
3032
getAutoPreprocess({
31-
test({ content }) {
33+
test() {
3234
return { code: '' };
3335
},
3436
}),
3537
);
38+
3639
expect(preprocessed.toString()).toBe('<script></script><style></style>');
3740
});
3841

@@ -44,13 +47,15 @@ MARKUP_LANGS.forEach(([lang, ext]) => {
4447

4548
it(`should throw parsing ${lang} when { ${lang}: false }`, async () => {
4649
const opts = getAutoPreprocess({ pug: false });
50+
4751
expect(await doesCompileThrow(template, opts)).toBe(true);
4852
});
4953

5054
it(`should parse ${lang}`, async () => {
5155
const preprocessed = (await preprocess(template, getAutoPreprocess()))
5256
.toString()
5357
.trim();
58+
5459
expect(preprocessed.toString()).toBe(EXPECTED_MARKUP);
5560
});
5661
});

test/autoProcess/script.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import getAutoPreprocess from '../../src';
22
import { preprocess, getFixtureContent, doesCompileThrow } from '../utils';
33

4-
const SCRIPT_LANGS: [string, string, object?][] = [
4+
const SCRIPT_LANGS: Array<[string, string, object?]> = [
55
['coffeescript', 'coffee'],
66
[
77
'typescript',
@@ -14,7 +14,7 @@ const EXPECTED_SCRIPT = getFixtureContent('script.js');
1414
SCRIPT_LANGS.forEach(([lang, ext, langOptions]) => {
1515
describe(`script - preprocessor - ${lang}`, () => {
1616
const template = `<div></div><script lang="${lang}">${getFixtureContent(
17-
'script.' + ext,
17+
`script.${ext}`,
1818
)}</script>`;
1919

2020
it(`should throw parsing ${lang} when { ${lang}: false }`, async () => {
@@ -25,6 +25,7 @@ SCRIPT_LANGS.forEach(([lang, ext, langOptions]) => {
2525
const opts = getAutoPreprocess({
2626
[lang]: false,
2727
});
28+
2829
expect(await doesCompileThrow(input, opts)).toBe(true);
2930
});
3031

@@ -33,6 +34,7 @@ SCRIPT_LANGS.forEach(([lang, ext, langOptions]) => {
3334
[lang]: langOptions,
3435
});
3536
const preprocessed = await preprocess(template, opts);
37+
3638
expect(preprocessed.toString()).toContain(EXPECTED_SCRIPT);
3739
});
3840
});

test/autoProcess/style.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
CSS_PATTERN,
77
} from '../utils';
88

9-
const STYLE_LANGS: [string, string][] = [
9+
const STYLE_LANGS: Array<[string, string]> = [
1010
['sass', 'sass'],
1111
['less', 'less'],
1212
['scss', 'scss'],
@@ -16,26 +16,29 @@ const STYLE_LANGS: [string, string][] = [
1616
STYLE_LANGS.forEach(([lang, ext]) => {
1717
describe(`style - preprocessor - ${lang}`, () => {
1818
const template = `<div></div><style lang="${lang}">${getFixtureContent(
19-
'style.' + ext,
19+
`style.${ext}`,
2020
)}</style>`;
2121
const templateExternal = `<div></div><style src="./fixtures/style.${ext}"></style>`;
2222

2323
it(`should throw parsing ${lang} when { ${lang}: false }`, async () => {
2424
const opts = getAutoPreprocess({
2525
[lang]: false,
2626
});
27+
2728
expect(await doesCompileThrow(template, opts)).toBe(true);
2829
});
2930

3031
it(`should parse ${lang}`, async () => {
3132
const opts = getAutoPreprocess();
3233
const preprocessed = await preprocess(template, opts);
34+
3335
expect(preprocessed.toString()).toMatch(CSS_PATTERN);
3436
});
3537

3638
it(`should parse external ${lang}`, async () => {
3739
const opts = getAutoPreprocess();
3840
const preprocessed = await preprocess(templateExternal, opts);
41+
3942
expect(preprocessed.toString()).toMatch(CSS_PATTERN);
4043
});
4144
});

test/transformers/globalRule.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('transformer - globalRule', () => {
66
const template = `<style>:global div{color:red}:global .test{}</style>`;
77
const opts = autoProcess();
88

9-
expect(async () => await preprocess(template, opts)).not.toThrow();
9+
expect(() => preprocess(template, opts)).not.toThrow();
1010
});
1111

1212
it('wraps selector in :global(...) modifier', async () => {

test/transformers/globalStyle.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('transformer - globalStyle', () => {
66
const template = `<style global>div{color:red}.test{}</style>`;
77
const opts = autoProcess();
88
const preprocessed = await preprocess(template, opts);
9+
910
expect(preprocessed.toString()).toContain(
1011
`:global(div){color:red}:global(.test){}`,
1112
);
@@ -15,6 +16,7 @@ describe('transformer - globalStyle', () => {
1516
const template = `<style global>.test{}:global(.foo){}</style>`;
1617
const opts = autoProcess();
1718
const preprocessed = await preprocess(template, opts);
19+
1820
expect(preprocessed.toString()).toContain(
1921
`:global(.test){}:global(.foo){}`,
2022
);
@@ -26,6 +28,7 @@ describe('transformer - globalStyle', () => {
2628
</style>`;
2729
const opts = autoProcess();
2830
const preprocessed = await preprocess(template, opts);
31+
2932
expect(preprocessed.toString()).toContain(
3033
`@keyframes -global-a {from{} to{}}@keyframes -global-b {from{} to{}}`,
3134
);
@@ -35,13 +38,15 @@ describe('transformer - globalStyle', () => {
3538
const template = `<style global>:local(div) .test{}</style>`;
3639
const opts = autoProcess();
3740
const preprocessed = await preprocess(template, opts);
41+
3842
expect(preprocessed.toString()).toContain(`div :global(.test){}`);
3943
});
4044

4145
it('allows to use :local() in the middle of a selector', async () => {
4246
const template = `<style global>.test :local(div) .test{}</style>`;
4347
const opts = autoProcess();
4448
const preprocessed = await preprocess(template, opts);
49+
4550
expect(preprocessed.toString()).toContain(
4651
`:global(.test) div :global(.test){}`,
4752
);
@@ -51,6 +56,7 @@ describe('transformer - globalStyle', () => {
5156
const template = `<style global>.test :local(div){}</style>`;
5257
const opts = autoProcess();
5358
const preprocessed = await preprocess(template, opts);
59+
5460
expect(preprocessed.toString()).toContain(`:global(.test) div{}`);
5561
});
5662
});

test/transformers/less.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { preprocess } from '../utils';
55

66
describe('transformer - less', () => {
77
// TODO: waiting for https://github.com/less/less.js/issues/3508
8+
// eslint-disable-next-line jest/no-disabled-tests
89
it.skip('should return @imported files as dependencies', async () => {
910
const template = `<style lang="less">@import "fixtures/style.less";</style>`;
1011
const opts = getAutoPreprocess();

test/transformers/postcss.test.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,65 @@
1+
/* eslint-disable global-require */
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
/* eslint-disable @typescript-eslint/no-require-imports */
14
import { resolve } from 'path';
25

36
import getAutoPreprocess from '../../src';
47
import { preprocess } from '../utils';
58

69
describe('transformer - postcss', () => {
7-
const template = `<div></div><style>div{appearance:none;}</style>`;
8-
const templateSass = `<div></div><style lang="scss">div{appearance:none;}</style>`;
9-
const optsWithoutConfigFile = getAutoPreprocess({
10-
postcss: {
11-
plugins: [
12-
require('autoprefixer')({
13-
overrideBrowserslist: 'Safari >= 5.1',
14-
}),
15-
],
16-
},
17-
});
18-
1910
it('should not transform plain css with postcss if { postcss: falsy }', async () => {
11+
const template = `<div></div><style>div{appearance:none;}</style>`;
2012
const preprocessed = await preprocess(template, getAutoPreprocess());
13+
2114
expect(preprocessed.toString()).not.toMatch(/-webkit-/);
2215
});
2316

2417
it('should not transform plain css with postcss if { postcss: true } and no configuration file at cwd', async () => {
18+
const template = `<div></div><style>div{appearance:none;}</style>`;
2519
const preprocessed = await preprocess(
2620
template,
2721
getAutoPreprocess({
2822
postcss: true,
2923
}),
3024
);
25+
3126
expect(preprocessed.toString()).not.toMatch(/-webkit-/);
3227
});
3328

3429
it('should transform plain css with postcss if { postcss: { plugins... } }', async () => {
30+
const template = `<div></div><style>div{appearance:none;}</style>`;
31+
const optsWithoutConfigFile = getAutoPreprocess({
32+
postcss: {
33+
plugins: [
34+
require('autoprefixer')({
35+
overrideBrowserslist: 'Safari >= 5.1',
36+
}),
37+
],
38+
},
39+
});
3540
const preprocessed = await preprocess(template, optsWithoutConfigFile);
41+
3642
expect(preprocessed.toString()).toMatch(/-webkit-/);
3743
});
3844

3945
it('should transform async preprocessed css with postcss if { postcss: { plugins... } }', async () => {
46+
const templateSass = `<div></div><style lang="scss">div{appearance:none;}</style>`;
47+
const optsWithoutConfigFile = getAutoPreprocess({
48+
postcss: {
49+
plugins: [
50+
require('autoprefixer')({
51+
overrideBrowserslist: 'Safari >= 5.1',
52+
}),
53+
],
54+
},
55+
});
4056
const preprocessed = await preprocess(templateSass, optsWithoutConfigFile);
57+
4158
expect(preprocessed.toString()).toMatch(/-webkit-/);
4259
});
4360

4461
it('should transform plain css with postcss if { postcss: { configFilePath: ... } }', async () => {
62+
const template = `<div></div><style>div{appearance:none;}</style>`;
4563
const preprocessed = await preprocess(
4664
template,
4765
getAutoPreprocess({
@@ -50,6 +68,7 @@ describe('transformer - postcss', () => {
5068
},
5169
}),
5270
);
71+
5372
expect(preprocessed.toString()).toMatch(/-webkit-/);
5473
});
5574

@@ -61,6 +80,7 @@ describe('transformer - postcss', () => {
6180
},
6281
});
6382
const preprocessed = await preprocess(template, opts);
83+
6484
expect(preprocessed.dependencies).toContain(
6585
resolve(__dirname, '..', 'fixtures', 'style.css'),
6686
);
@@ -78,6 +98,7 @@ div
7898
},
7999
});
80100
const preprocessed = await preprocess(template, opts);
101+
81102
expect(preprocessed.toString()).toContain(`div {
82103
color: red
83104
}`);

0 commit comments

Comments
 (0)