Skip to content

Commit ee53057

Browse files
committed
Fix ESLint issues
1 parent 9ad067c commit ee53057

File tree

11 files changed

+26
-21
lines changed

11 files changed

+26
-21
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"parser": "@typescript-eslint/parser",
1111
"parserOptions": {
1212
"project": ["./tsconfig.json"]
13-
}
13+
},
14+
"ignorePatterns": ["dist", "jest.config.js", "src/helpers/__tests__/fixtures"]
1415
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
],
2727
"scripts": {
2828
"build": "rm -rf ./dist && tsc --project tsconfig.build.json",
29-
"lint": "eslint --max-warnings 0 . && yarn prettier -c .",
30-
"prepublishOnly": "yarn build",
29+
"lint": "eslint --max-warnings 0 . && pnpm prettier -c .",
30+
"prepublishOnly": "pnpm build",
3131
"test": "jest",
3232
"prepare": "husky install"
3333
},

src/helpers/createDtsExports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default classes;
5555
const smc = new SourceMapConsumer(cssExports.sourceMap);
5656

5757
// Split original CSS file into lines.
58-
const cssLines = cssExports.css?.split('\n') || [];
58+
const cssLines = cssExports.css?.split('\n') ?? [];
5959

6060
// Create new equal size array of empty strings.
6161
const dtsLines = Array.from(Array(cssLines.length), () => '');

src/helpers/getCssExports.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const getCssExports = ({
5252
}): CSSExportsWithSourceMap => {
5353
try {
5454
const fileType = getFileType(fileName);
55-
const rendererOptions = options.rendererOptions || {};
55+
const rendererOptions = options.rendererOptions ?? {};
5656

5757
let transformedCss = '';
5858
let sourceMap: RawSourceMap | undefined;
@@ -73,7 +73,7 @@ export const getCssExports = ({
7373
{
7474
syncImport: true,
7575
filename: fileName,
76-
...(rendererOptions.less || {}),
76+
...(rendererOptions.less ?? {}),
7777
} as Less.Options,
7878
(
7979
error: Less.RenderError | undefined,
@@ -93,7 +93,7 @@ export const getCssExports = ({
9393
case FileType.scss:
9494
case FileType.sass: {
9595
const filePath = getFilePath(fileName);
96-
const { loadPaths, ...sassOptions } = rendererOptions.sass || {};
96+
const { loadPaths, ...sassOptions } = rendererOptions.sass ?? {};
9797
const { baseUrl, paths } = compilerOptions;
9898
const matchPath =
9999
baseUrl && paths
@@ -111,7 +111,7 @@ export const getCssExports = ({
111111

112112
const result = sass.compile(fileName, {
113113
importers,
114-
loadPaths: [filePath, 'node_modules', ...(loadPaths || [])],
114+
loadPaths: [filePath, 'node_modules', ...(loadPaths ?? [])],
115115
sourceMap: true,
116116
// sourceMapIncludeSources: true,
117117
...sassOptions,
@@ -124,7 +124,7 @@ export const getCssExports = ({
124124

125125
case FileType.styl:
126126
transformedCss = stylus(css, {
127-
...(rendererOptions.stylus || {}),
127+
...(rendererOptions.stylus ?? {}),
128128
filename: fileName,
129129
}).render();
130130
break;

src/helpers/getDtsSnapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const getDtsSnapshot = (
2121
* https://github.com/mrmckeb/typescript-plugin-css-modules/issues/41
2222
* Needs investigation for a more elegant solution.
2323
*/
24-
if (/export default classes/.test(css)) {
24+
if (css.includes('export default classes')) {
2525
return scriptSnapshot;
2626
}
2727

src/helpers/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const createLogger = (info: ts.server.PluginCreateInfo): Logger => {
1010
);
1111
};
1212
const error = (error: unknown) => {
13-
log(`Failed with error: ${error}`);
13+
log(`Failed with error: ${error as string}`);
1414
};
1515

1616
return {

src/helpers/validVarRegexp.ts

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const getPostCssConfigPlugins = (directory: string) => {
2020
}
2121
};
2222

23-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
2423
function init({ typescript: ts }: { typescript: typeof tsModule }) {
2524
let _isCSS: isCSSFn;
2625

@@ -33,16 +32,18 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
3332
process.chdir(directory);
3433

3534
// User options for plugin.
36-
const options: Options = info.config.options || {};
35+
36+
const config = info.config as { options?: Options };
37+
const options = config.options ?? {};
3738
logger.log(`options: ${JSON.stringify(options)}`);
3839

3940
// Load environment variables like SASS_PATH.
4041
// TODO: Add tests for this option.
41-
const dotenvOptions = options.dotenvOptions || {};
42+
const dotenvOptions = options.dotenvOptions;
4243
if (dotenvOptions) {
4344
dotenvOptions.path = path.resolve(
4445
directory,
45-
dotenvOptions.path || '.env',
46+
dotenvOptions.path ?? '.env',
4647
);
4748
}
4849
dotenv.config(dotenvOptions);
@@ -60,7 +61,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
6061

6162
// Add postCSS config if enabled.
6263
const postcssOptions =
63-
options.postcssOptions || options.postCssOptions || {};
64+
options.postcssOptions ?? options.postCssOptions ?? {};
6465

6566
let userPlugins: AcceptedPlugin[] = [];
6667
if (postcssOptions.useConfig) {
@@ -212,7 +213,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
212213

213214
// Filter to only one extension type, and remove that extension. This leaves us with the actual filename.
214215
// Example: "usr/person/project/src/dir/File.module.css/index.d.ts" > "usr/person/project/src/dir/File.module.css"
215-
const normalizedLocations = failedLocations.reduce(
216+
const normalizedLocations = failedLocations.reduce<string[]>(
216217
(locations, location) => {
217218
if (
218219
(baseUrl ? location.includes(baseUrl) : true) &&
@@ -222,7 +223,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
222223
}
223224
return locations;
224225
},
225-
[] as string[],
226+
[],
226227
);
227228

228229
// Find the imported CSS module, if it exists.

src/setup-tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// TODO: Remove this when the related issue is resolved.
22
// https://github.com/css-modules/postcss-icss-keyframes/issues/3
3+
// eslint-disable-next-line @typescript-eslint/unbound-method
34
const warn = global.console.warn;
45
global.console.warn = (...args: unknown[]) => {
56
const isPostCSSDeprecationWarning =

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["**/__tests__/**", "setup-tests.js"]
3+
"exclude": ["dist", "**/__tests__/**", "setup-tests.js"]
44
}

0 commit comments

Comments
 (0)