Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] update eslint rules and commands for src #1766

Merged
merged 5 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/xarc-app-dev/src/config/eslint/.eslintrc-base
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
extends:
- "./js/base.js"
rules:
"func-style": ["off"]
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ rules:
"max-statements": "off"
"max-nested-callbacks": "off"
"no-multi-spaces": "off"
"func-style": ["off"]
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ rules:
"max-nested-callbacks": "off"
"prefer-arrow-callback": "off"
"no-multi-spaces": "off"
"func-style": ["off"]
25 changes: 22 additions & 3 deletions packages/xarc-app-dev/src/config/eslint/.eslintrc-react
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
---
extends:
- "./js/es6-react.js"
- "plugin:react/recommended"
globals:
window: false
document: false
ReactElement: false
plugins: [
"flowtype"
]
env:
mocha: true
plugins:
- flowtype
- react
rules:
"maxlen": "off"
"react/jsx-boolean-value": "off"
"react/jsx-closing-bracket-location": "off"
"react/no-string-refs": "off"
Expand All @@ -20,3 +24,18 @@ rules:
"flowtype/define-flow-type": "warn"
"flowtype/use-flow-type": "warn"
"flowtype/require-valid-file-annotation": "error"
"func-style": ["off"]
"settings":
"react":
"createClass": "createReactClass"
"pragma": "React"
"fragment": "Fragment"
"version": "detect"
"flowVersion": "0.53"
"propWrapperFunctions":
- "forbidExtraProps"
- {"property": "freeze", "object": "Object"}
- {"property": "myFavoriteWrapper"}
"linkComponents":
- "Hyperlink"
- {"name": "Link", "linkAttribute": "to"}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ rules:
"flowtype/define-flow-type": "warn"
"flowtype/use-flow-type": "warn"
"flowtype/require-valid-file-annotation": "error"
"func-style": ["off"]
11 changes: 7 additions & 4 deletions packages/xarc-app-dev/src/config/eslint/.eslintrc-react-test
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ globals:
expect: false
sinon: false
Element: false
plugins: [
"flowtype"
]
env:
mocha: true
plugins:
- flowtype
- react
rules:
"no-unused-expressions": "off" # for `chai.expect`
"max-len": ["error", 100, 2, {ignorePattern: "^\\s*(?:it|describe)\\(.*"}]
"max-len": "off"
"max-statements": "off"
"max-nested-callbacks": "off"
"react/jsx-wrap-multilines": "warn"
Expand All @@ -21,3 +23,4 @@ rules:
"flowtype/define-flow-type": "warn"
"flowtype/use-flow-type": "warn"
"flowtype/require-valid-file-annotation": "error"
"func-style": ["off"]
95 changes: 68 additions & 27 deletions packages/xarc-app-dev/src/lib/dev-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,23 @@ export function loadXarcDevTasks(xrun, userOptions: XarcOptions = {}) {
{ custom: [], archetype: [] }
);

const ignorePattern = options.ignorePatterns
? options.ignorePatterns.map(p => `--ignore-pattern ${p}`)
: "";

const version = require("eslint/package.json")
.version.split(".")
.map(x => parseInt(x));
const noUnmatchError =
version[0] > 6 && version[1] > 8 ? ` --no-error-on-unmatched-pattern` : "";

const commands = [
grouped.custom.length > 0 && `~$eslint${ext} ${grouped.custom.join(" ")}`,
grouped.custom.length > 0 &&
`~$eslint${ext}${noUnmatchError} ${grouped.custom.join(" ")} ${ignorePattern}`,
grouped.archetype.length > 0 &&
`~$eslint${ext} --no-eslintrc -c ${options.config} ${grouped.archetype.join(" ")}`
`~$eslint${ext}${noUnmatchError} --no-eslintrc -c ${
options.config
} ${grouped.archetype.join(" ")} ${ignorePattern}`
];

return Promise.resolve(commands.filter(x => x));
Expand Down Expand Up @@ -1040,50 +1053,78 @@ You only need to run this if you are doing something not through the xarc tasks.
}

if (xarcOptions.options.eslint) {
const hasTest = Fs.existsSync("test");
const hasTestServer = Fs.existsSync("test/server");
// legacy src/client and src/server only setup?
let isLegacySrc = false;
try {
const files = Fs.readdirSync("src").filter(x => !x.startsWith("."));
isLegacySrc = files.sort().join("") === "clientserver";
} catch (err) {
//
}

const lintTasks = [
"lint-client",
hasTest && "lint-client-test",
"lint-server",
hasTestServer && "lint-server-test"
].filter(x => x);

Object.assign(tasks, {
lint: xclap2.concurrent(
"lint-client",
"lint-client-test",
"lint-server",
"lint-server-test"
),
lint: xclap2.concurrent(...lintTasks),

"lint-client": {
desc: "Run eslint on client code in directories client and templates",
desc:
"Run eslint on code in src/client and templates with react rules (ignore src/server)",
task: () =>
lint({
ext: ".js,.jsx",
ext: ".js,.jsx,.ts,.tsx",
config: eslintConfig(".eslintrc-react"),
targets: [AppMode.src.client, "templates"]
})
},
"lint-client-test": {
desc: "Run eslint on client test code in directory test/client",
task: () =>
lint({
ext: ".js,.jsx",
config: eslintConfig(".eslintrc-react-test"),
targets: ["test/client", ...jestTestDirectories.map(dir => `${dir}/client`)]
targets: isLegacySrc
? [AppMode.src.client, "templates"]
: [AppMode.src.dir, "templates"],
ignorePatterns: [AppMode.src.server]
})
},

"lint-server": {
desc: "Run eslint on server code in directory server",
desc: "Run eslint on server code in src/server with node.js rules",
task: () =>
lint({
ext: ".js,.jsx,.ts,.tsx",
config: eslintConfig(".eslintrc-node"),
targets: [AppMode.src.server]
})
},
"lint-server-test": {
desc: "Run eslint on server test code in directories test/server and test/func",
}
});

if (hasTest) {
tasks["lint-client-test"] = {
desc: "Run eslint on code in test with react rules (ignore test/server)",
task: () =>
lint({
ext: ".js,.jsx,.ts,.tsx",
config: eslintConfig(".eslintrc-react-test"),
targets: ["test", ...jestTestDirectories.map(dir => `${dir}`)],
ignorePatterns: ["test/server"]
})
};
}

if (hasTestServer) {
tasks["lint-server-test"] = {
desc: "Run eslint on code in in test/server with node.js rules",
task: () =>
lint({
ext: ".js,.jsx,.ts,.tsx",
config: process.env.SERVER_ES6
? eslintConfig(".eslintrc-mocha-test-es6")
: eslintConfig(".eslintrc-mocha-test"),
targets: ["test/server", "test/func"]
targets: ["test/server"]
})
}
});
};
}
} else {
const lintDisabled = () => {
logger.info(`eslint tasks are disabled because @xarc/opt-eslint is not installed.
Expand Down
13 changes: 7 additions & 6 deletions samples/universal-react-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@
},
"devDependencies": {
"@xarc/app-dev": "^7.0.5",
"redux-devtools": "^3.3.1",
"redux-devtools-dock-monitor": "^1.1.1",
"redux-devtools-log-monitor": "^1.0.11",
"@xarc/opt-eslint": "^1.0.0",
"electrode-archetype-opt-critical-css": "^1.0.3",
"electrode-archetype-opt-eslint": "^1.0.3",
"electrode-archetype-opt-flow": "^1.0.2",
"electrode-archetype-opt-jest": "^24.0.0",
"electrode-archetype-opt-karma": "^2.0.6",
Expand All @@ -71,7 +68,10 @@
"electrode-archetype-opt-pwa": "^1.0.6",
"electrode-archetype-opt-sinon": "^1.0.3",
"electrode-archetype-opt-stylus": "^1.0.2",
"electrode-archetype-opt-typescript": "^1.0.3"
"electrode-archetype-opt-typescript": "^1.0.3",
"redux-devtools": "^3.3.1",
"redux-devtools-dock-monitor": "^1.1.1",
"redux-devtools-log-monitor": "^1.0.11"
},
"fyn": {
"dependencies": {
Expand All @@ -81,7 +81,8 @@
"react-vendor-dll": "../react-vendor-dll"
},
"devDependencies": {
"@xarc/app-dev": "../../packages/xarc-app-dev"
"@xarc/app-dev": "../../packages/xarc-app-dev",
"@xarc/opt-eslint": "../../packages/xarc-opt-eslint"
}
},
"optionalDependencies": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class AboveFold extends React.Component {
<a
href="https://github.com/electrode-io/above-the-fold-only-server-render"
target="_blank"
rel="noreferrer"
>
Read more about this module and see our live demo
</a>
Expand All @@ -53,8 +54,8 @@ export class AboveFold extends React.Component {
and it always will be rendered on server side.
</p>
<p>
To verify, use your browser's view source to see the original HTML of this page and see
this being part of the SSR content
To verify, use your browser&apos;s view source to see the original HTML of this page and
see this being part of the SSR content
</p>
<p>
You should see this fill up your browser screen to push content below the browser view
Expand All @@ -70,7 +71,7 @@ export class AboveFold extends React.Component {
</div>
{this.props.skip ? (
<div>
In the page source you should NOT see any more HTML after this except a few empty{" "}
In the page source you should NOT see any more HTML after this except a few empty
<span>divs</span>
</div>
) : (
Expand All @@ -92,7 +93,7 @@ export class AboveFold extends React.Component {
}}
>
<p>
This content block is wrapped inside the <span>AboveTheFoldOnlyServerRender</span>{" "}
This content block is wrapped inside the <span>AboveTheFoldOnlyServerRender</span>
component, with the
<span> skip</span> prop set to <span>{`${this.props.skip}`}</span>.
</p>
Expand Down
10 changes: 5 additions & 5 deletions samples/universal-react-node/src/client/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import electrodeLogo from "../images/electrode.svg";
import Notifications from "react-notify-toast";

type HomeProps = {
data: string
data: string;
};

/* eslint-disable max-len */
Expand Down Expand Up @@ -40,14 +40,14 @@ export class Home extends Component<HomeProps> {
</li>
<li>
<a href="/above-the-fold?skip=true">
Above the Fold Render with skip=true - increase your App's performance by using a skip
prop
Above the Fold Render with skip=true - increase your App&apos;s performance by using a
skip prop
</a>
</li>
<li>
<a href="/above-the-fold?skip=false">
Above the Fold Render with skip=false - increase your App's performance by using a
skip prop
Above the Fold Render with skip=false - increase your App&apos;s performance by using
a skip prop
</a>
</li>
<li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @flow

/* eslint-disable react/display-name */

import React from "react";
import { createDevTools } from "redux-devtools";
import LogMonitor from "redux-devtools-log-monitor";
Expand Down
2 changes: 2 additions & 0 deletions samples/universal-react-node/src/server/routes/init-top.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-magic-numbers */

import reducer from "../../client/reducers";
import Promise from "bluebird";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function(options) {
export default function(/*options*/) {
return {
reducer: {},
initialState: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function(options) {
export default function(/*options*/) {
return {
reducer: {},
initialState: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from "path";

const readFile = Promise.promisify(fs.readFile);

export default async function(options) {
export default async function(/*options*/) {
let storage;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Home", () => {
});

it("has expected content with deep render", () => {
component = ReactDOM.render(<Home />, container);
component = ReactDOM.render(<Home />, container); // eslint-disable-line react/no-render-return-value

expect(component).to.not.be.false;
});
Expand Down