Skip to content

Commit

Permalink
feat: create core/base for react/node/legacy lint configs (microsoft#…
Browse files Browse the repository at this point in the history
…22128)

* feat: create core base for react/node/legacy lint configs

* style: fix lint errors

* generate change files

* create base and base-legacy configs

* feat: make imports config public

* undo changes

* docs(eslint-plugin): update docs
  • Loading branch information
Hotell authored and marwan38 committed Jun 13, 2022
1 parent cf561cc commit 1a3c6b3
Show file tree
Hide file tree
Showing 18 changed files with 611 additions and 455 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "style: fix lint errors",
"packageName": "@fluentui/api-docs",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "style: fix lint errors",
"packageName": "@fluentui/codemods",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: create core base for react/node/legacy lint configs",
"packageName": "@fluentui/eslint-plugin",
"email": "[email protected]",
"dependentChangeType": "none"
}
3 changes: 3 additions & 0 deletions packages/api-docs/src/generatePageJsonFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function generatePageJsonFiles(options: IPageJsonOptions): void {
// Load api-extractor output from packages into a model
const apiModel = new ApiModel();
for (const apiJsonPath of apiJsonPaths) {
// eslint-disable-next-line no-console
console.log('Loading ' + apiJsonPath);

// If the file belongs to the compat layer.
Expand Down Expand Up @@ -53,6 +54,7 @@ export function generatePageJsonFiles(options: IPageJsonOptions): void {
const requestedPages = ([] as string[]).concat(...Object.values(pageGroups));
for (const pageName of requestedPages) {
if (!pageJsonByName.has(pageName)) {
// eslint-disable-next-line no-console
console.warn('Warning: no API items found for expected @docCategory ' + pageName);
}
}
Expand All @@ -61,6 +63,7 @@ export function generatePageJsonFiles(options: IPageJsonOptions): void {
for (const [pageName, pageJson] of pageJsonByName.entries()) {
const pageJsonPath = path.join(outputRoot, pageJson.group || '', pageName + '.page.json');

// eslint-disable-next-line no-console
console.log('Writing ' + pageJsonPath);
const json = min ? JSON.stringify(pageJson) : JSON.stringify(pageJson, null, 2);
fse.writeFileSync(pageJsonPath, json);
Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/node"],
"extends": ["plugin:@fluentui/eslint-plugin/node", "plugin:@fluentui/eslint-plugin/react"],
"root": true,
"overrides": [
{
Expand Down
4 changes: 4 additions & 0 deletions packages/codemods/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ export class CommandParser {
}
if (parsed.list) {
const mods = getEnabledMods(console, getModsPaths);
// eslint-disable-next-line no-console
console.log('Here are the enabled code mod names:\n');
mods.forEach(mod => {
// eslint-disable-next-line no-console
console.log(mod.name);
});
return { shouldExit: true, modsFilter: () => true };
Expand All @@ -86,6 +88,7 @@ export class CommandParser {
if (configResult.ok) {
configObj = configResult.value;
} else {
// eslint-disable-next-line no-console
console.log(configResult.value);
return { shouldExit: true, modsFilter: () => true };
}
Expand Down Expand Up @@ -115,6 +118,7 @@ function getModRunnerConfig(): Result<ModRunnerConfigType, ModError> {
sync: true,
});
let configObj: ModRunnerConfigType = { stringFilters: [], regexFilters: [], includeMods: false };
// eslint-disable-next-line no-console
console.log('Configuration detected. Attempting to run mods from config...');
if (!foundJsonFile.found || foundJsonFile.found.length !== 1) {
return Err<ModRunnerConfigType, ModError>({ error: new Error('Error, could not locate correct config file.') });
Expand Down
9 changes: 5 additions & 4 deletions packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

Usage: in your [ESLint config file](https://eslint.org/docs/user-guide/configuring), add `{ "extends": ["plugin:@fluentui/<name>"] }` or `{ "extends": ["plugin:@fluentui/eslint-plugin/<name>"] }` (the two are equivalent).

- `react`: For `@fluentui/react` and related packages
- `react--legacy`: Like `react` but requiring an `I` prefix for interfaces
- `node`: Like `react` but for packages which run in a Node environment (not the browser)
- `node--legacy`: Like `node` but requiring an `I` prefix for interfaces
- `react`: react specific configuration for fluentui vNext
- `node`: node specific configuration for fluentui vNext
- `react--legacy`: react specific configuration for fluentui v7,8
- `node--legacy`: node specific configuration for fluentui v7,8
- `react-northstar`: For `@fluentui/react-northstar` and related packages
- `imports`: auto import statements sorting configuration

Helpers for customizing configuration are exported under a `configHelpers` object.

Expand Down
18 changes: 18 additions & 0 deletions packages/eslint-plugin/src/configs/base-legacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-check

const path = require('path');

const { getNamingConventionRule } = require('../utils/configHelpers');

/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [path.join(__dirname, 'core')],
rules: {
/**
* `@typescript-eslint`plugin eslint rules
* @see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin
*/
...getNamingConventionRule({ prefixInterface: true }),
},
overrides: [],
};
26 changes: 26 additions & 0 deletions packages/eslint-plugin/src/configs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @ts-check

const path = require('path');

const { getNamingConventionRule } = require('../utils/configHelpers');

/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [path.join(__dirname, 'core')],
rules: {
/**
* `@typescript-eslint`plugin eslint rules
* @see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin
*/
...getNamingConventionRule(),
},
overrides: [
{
files: '**/src/index.{ts,tsx,js}',
rules: {
// TODO: propagate to `error` once all packages barrel files have been fixed
'@rnx-kit/no-export-all': ['warn', { expand: 'all' }],
},
},
],
};
Loading

0 comments on commit 1a3c6b3

Please sign in to comment.