Skip to content

Commit

Permalink
eslint fixes (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackleadsu authored Jul 16, 2020
1 parent 4476837 commit 2ccf13e
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 104 deletions.
23 changes: 12 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module.exports = {
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
],
env: {
node: true
node: true,
},
parserOptions: {
ecmaVersion: 8
ecmaVersion: 8,
},
rules: {
"prettier/prettier": "error",
Expand All @@ -19,6 +19,7 @@ module.exports = {
"no-template-curly-in-string": "error",
"no-caller": "error",
"no-control-regex": "off",
"no-async-promise-executor": "off",
yoda: "error",
eqeqeq: "error",
"global-require": "off",
Expand All @@ -30,8 +31,8 @@ module.exports = {
"no-unused-vars": [
"error",
{
args: "none"
}
args: "none",
},
],
"no-unsafe-negation": "error",
"no-loop-func": "warn",
Expand All @@ -47,19 +48,19 @@ module.exports = {
class: "DONTUSE",
inheritdoc: "DONTUSE",
description: "DONTUSE",
readonly: "DONTUSE"
readonly: "DONTUSE",
},
preferType: {
"*": "any"
"*": "any",
},
requireReturnType: true
}
requireReturnType: true,
},
],
"node/no-unsupported-features": "error",
"node/no-deprecated-api": "error",
"node/no-missing-import": "error",
"node/no-unpublished-bin": "error",
"node/no-unpublished-require": "error",
"node/process-exit-as-throw": "error"
}
"node/process-exit-as-throw": "error",
},
};
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run eslint
env:
CI: true
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# powerbi-visuals-webpack-plugin

[![npm version](https://img.shields.io/npm/v/powerbi-visuals-webpack-plugin.svg)](https://www.npmjs.com/package/powerbi-visuals-webpack-plugin) [![npm](https://img.shields.io/npm/dm/powerbi-visuals-webpack-plugin.svg)](https://www.npmjs.com/package/powerbi-visuals-webpack-plugin)
![Build](https://github.com/microsoft/powerbi-visuals-webpack-plugin/workflows/build/badge.svg) [![npm version](https://img.shields.io/npm/v/powerbi-visuals-webpack-plugin.svg)](https://www.npmjs.com/package/powerbi-visuals-webpack-plugin) [![npm](https://img.shields.io/npm/dm/powerbi-visuals-webpack-plugin.svg)](https://www.npmjs.com/package/powerbi-visuals-webpack-plugin)

This plugin allows developing custom visuals by using webpack to build a visual package.

Expand Down
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
ENCODING: "utf-8"
ENCODING: "utf-8",
};
6 changes: 3 additions & 3 deletions extractor/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require("path");
const fs = require("fs-extra");
const logger = require("../logger");

const getSchema = async function(options) {
const getSchema = async function (options) {
if (options.capabilitiesSchema)
return Promise.resolve(options.capabilitiesSchema);

Expand All @@ -12,7 +12,7 @@ const getSchema = async function(options) {
);
};

module.exports = async function(options) {
module.exports = async function (options) {
let getContent;
switch (typeof options.capabilities) {
case "string": {
Expand All @@ -34,7 +34,7 @@ module.exports = async function(options) {
const ajv = new Ajv({ extendRefs: true });
const valid = ajv.validate(schema, json);
if (valid) return json;
ajv.errors.forEach(error =>
ajv.errors.forEach((error) =>
logger.error(error.message, error.dataPath)
);

Expand Down
4 changes: 2 additions & 2 deletions extractor/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const RawSource = require("webpack-sources/lib/RawSource");

const { ENCODING } = require("../constants");

module.exports = async function(options, { assets }) {
module.exports = async function (options, { assets }) {
let chunkContent, result;

for (let asset in assets) {
Expand All @@ -17,7 +17,7 @@ module.exports = async function(options, { assets }) {
if (!chunkContent) {
if (options.cssStyles) {
result = fs.readFile(options.cssStyles, {
encoding: ENCODING
encoding: ENCODING,
});
} else {
assets["visual.css"] = new RawSource("");
Expand Down
8 changes: 4 additions & 4 deletions extractor/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require("path");
const fs = require("fs-extra");
const logger = require("../logger");

const getSchema = async function(options) {
const getSchema = async function (options) {
if (options.dependenciesSchema)
return Promise.resolve(options.dependenciesSchema);

Expand All @@ -12,15 +12,15 @@ const getSchema = async function(options) {
);
};

module.exports = async function(options) {
module.exports = async function (options) {
if (!options.dependencies) return Promise.resolve(null);

let getContent;
switch (typeof options.dependencies) {
case "string": {
getContent = fs
.readJson(path.join(process.cwd(), options.dependencies))
.catch(err => {
.catch((err) => {
if (err.code === "ENOENT") {
logger.warn(
`No such file or directory: ${path.join(
Expand All @@ -46,7 +46,7 @@ module.exports = async function(options) {
const ajv = new Ajv({ extendRefs: true });
const valid = ajv.validate(schema, json);
if (valid) return json;
ajv.errors.forEach(error =>
ajv.errors.forEach((error) =>
logger.error(error.message, error.dataPath)
);

Expand Down
12 changes: 6 additions & 6 deletions extractor/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ const RawSource = require("webpack-sources/lib/RawSource");
const { ENCODING } = require("../constants");
const logger = require("../logger");

const appendExternalJS = async function(externalJS) {
const appendExternalJS = async function (externalJS) {
return Promise.all(
externalJS.map(path =>
fs.readFile(path, ENCODING).catch(err => {
externalJS.map((path) =>
fs.readFile(path, ENCODING).catch((err) => {
logger.warn(err.message);
})
)
).then(results => results.join(""));
).then((results) => results.join(""));
};

module.exports = async function(options, compilation) {
module.exports = async function (options, compilation) {
let path, chunkContent;
const sourcePromises = [];

Expand All @@ -33,7 +33,7 @@ module.exports = async function(options, compilation) {
}
sourcePromises.push(Promise.resolve(chunkContent));

return Promise.all(sourcePromises).then(chunks => {
return Promise.all(sourcePromises).then((chunks) => {
const content = chunks.join("\n");
compilation.assets[path] = new RawSource(content);
return content;
Expand Down
30 changes: 15 additions & 15 deletions extractor/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ const path = require("path");
const fs = require("fs-extra");
const { ENCODING } = require("../constants");

const parseFromProperty = async function(options) {
const parseFromProperty = async function (options) {
if (!options.stringResources || !options.stringResources.length) return;
return Promise.all(
options.stringResources.map(resourcePath => {
options.stringResources.map((resourcePath) => {
return fs
.readJSON(path.join(process.cwd(), resourcePath), {
throws: false,
encoding: ENCODING
encoding: ENCODING,
})
.catch(err => {
.catch((err) => {
console.error(err);
return;
});
})
);
};

const parseFromFolder = async function(options) {
const parseFromFolder = async function (options) {
const resourcesDir = path.join(process.cwd(), "stringResources");

return fs.readdir(resourcesDir).then(
folders =>
(folders) =>
Promise.all(
folders.map(folder => {
folders.map((folder) => {
return fs
.readJson(
path.join(
Expand All @@ -35,14 +35,14 @@ const parseFromFolder = async function(options) {
),
{
throws: false,
encoding: ENCODING
encoding: ENCODING,
}
)
.then(resource => ({
.then((resource) => ({
locale: folder,
values: resource
values: resource,
}))
.catch(err => {
.catch((err) => {
console.error(err);
return;
});
Expand All @@ -52,20 +52,20 @@ const parseFromFolder = async function(options) {
);
};

module.exports = async function(options) {
module.exports = async function (options) {
if (options.devMode) {
return;
}
return Promise.all([
parseFromProperty(options),
parseFromFolder(options)
parseFromFolder(options),
]).then(([source1 = [], source2 = []]) => {
const stringResources = Object.create(null);
source1.forEach(res => {
source1.forEach((res) => {
if (!res) return;
stringResources[res.locale] = res.values;
});
source2.forEach(res => {
source2.forEach((res) => {
if (!res) return;

if (stringResources[res.locale]) {
Expand Down
10 changes: 5 additions & 5 deletions extractor/scriptVisual.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const { ENCODING } = require("../constants");

const MAX_IMPORT_MODULES = 100;

const getContent = async filePath => {
const getContent = async (filePath) => {
const Pattern4FileName = /^[^#\n]*source\s*?\(\s*?['|"]([^()'"]*)['|"]\s*?\)/m;

return fs.readFile(filePath, ENCODING).then(async content => {
return fs.readFile(filePath, ENCODING).then(async (content) => {
let replaceCount = 0;
let matchListFileName = Pattern4FileName.exec(content);
while (
Expand All @@ -28,7 +28,7 @@ const getContent = async filePath => {
});
};

const isScriptVisual = capabilities => {
const isScriptVisual = (capabilities) => {
return (
capabilities &&
capabilities.dataViewMappings &&
Expand All @@ -37,7 +37,7 @@ const isScriptVisual = capabilities => {
);
};

const getFileExtension = providerName => {
const getFileExtension = (providerName) => {
providerName = providerName.toLowerCase();
switch (providerName) {
case "r":
Expand Down Expand Up @@ -71,5 +71,5 @@ const patchCababilities = async (options, capabilities) => {
module.exports = {
getContent,
isScriptVisual,
patchCababilities
patchCababilities,
};
Loading

0 comments on commit 2ccf13e

Please sign in to comment.