Skip to content

Commit

Permalink
chore: update @ionic/prettier-config (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Dec 8, 2021
1 parent edc8cdb commit e5bb5ce
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 273 deletions.
22 changes: 13 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"devDependencies": {
"@capacitor/cli": "^3.0.1",
"@ionic/prettier-config": "^1.0.1",
"@ionic/prettier-config": "^2.0.0",
"@stencil/core": "^2.6.0",
"@types/github-slugger": "^1.3.0",
"@types/jest": "^26.0.23",
Expand Down
12 changes: 4 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ export async function run(config: { cwd: string; args: string[] }) {

try {
if (!args.api) {
throw new Error(
`Please provide the primary interface name using the "--api" arg`,
);
throw new Error(`Please provide the primary interface name using the "--api" arg`);
}

const tsconfigPath = getTsconfigPath(config.cwd, args.project);
if (!tsconfigPath) {
throw new Error(
`Unable to find project's tsconfig.json file. Use the "--project" arg to specify the exact path.`,
`Unable to find project's tsconfig.json file. Use the "--project" arg to specify the exact path.`
);
}

Expand All @@ -42,9 +40,7 @@ export async function run(config: { cwd: string; args: string[] }) {
};

if (!args['output-json'] && !args['output-readme']) {
throw new Error(
`Please provide an output path with either "--output-readme" or "--output-json" args, or both.`,
);
throw new Error(`Please provide an output path with either "--output-readme" or "--output-json" args, or both.`);
}

if (args['output-json']) {
Expand Down Expand Up @@ -74,7 +70,7 @@ function getTsconfigPath(cwd: string, cliTsConfigPath: string) {
if (cliTsConfigPath) {
return normalizePath(cwd, cliTsConfigPath);
}
return ts.findConfigFile(cwd, f => fs.existsSync(f));
return ts.findConfigFile(cwd, (f) => fs.existsSync(f));
}

function logOutput(outputPath: string | undefined) {
Expand Down
19 changes: 6 additions & 13 deletions src/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ export function formatType(data: DocsData, c: string | undefined) {
tokens.shift();
} else {
for (let i = tokens.length - 1; i >= 0; i--) {
if (
tokens[i] === 'undefined' &&
tokens[i - 1] === ' ' &&
tokens[i - 2] === '|' &&
tokens[i - 3] === ' '
) {
if (tokens[i] === 'undefined' && tokens[i - 1] === ' ' && tokens[i - 2] === '|' && tokens[i - 3] === ' ') {
tokens.splice(i - 3, 4);
i = i - 4;
}
Expand Down Expand Up @@ -92,25 +87,23 @@ export function formatMethodSignatureForSlug(m: DocsInterfaceMethod) {

function linkToken(data: DocsData, token: string) {
const t = token.replace(/`/g, '');
const i = data.interfaces.find(i => {
const i = data.interfaces.find((i) => {
return (
i.name === t ||
i.methods.some(m => i.name + '.' + m.name === t) ||
i.properties.some(p => i.name + '.' + p.name === t)
i.methods.some((m) => i.name + '.' + m.name === t) ||
i.properties.some((p) => i.name + '.' + p.name === t)
);
});
if (i) {
return `<a href="#${i.slug}">${token}</a>`;
}

const ta = data.typeAliases.find(ta => ta.name === t);
const ta = data.typeAliases.find((ta) => ta.name === t);
if (ta) {
return `<a href="#${ta.slug}">${token}</a>`;
}

const e = data.enums.find(
e => e.name === t || e.members.some(m => e.name + '.' + m.name === t),
);
const e = data.enums.find((e) => e.name === t || e.members.some((m) => e.name + '.' + m.name === t));
if (e) {
return `<a href="#${e.slug}">${token}</a>`;
}
Expand Down
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export { generate } from './generate';
export {
outputJson,
outputReadme,
replaceMarkdownPlaceholders,
} from './output';
export { outputJson, outputReadme, replaceMarkdownPlaceholders } from './output';
export { parse } from './parse';
export { run } from './cli';
export * from './types';
26 changes: 11 additions & 15 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class MarkdownTable {
addRow(data: string[], isHeader = false) {
const colData: ColumnData[] = [];

data.forEach(text => {
data.forEach((text) => {
const col: ColumnData = {
text: escapeMarkdownTableColumn(text),
width: text.length,
Expand Down Expand Up @@ -36,11 +36,7 @@ export class MarkdownTable {
const row = this.rows[r];
if (row && !row.isHeader) {
const column = row.columns[c];
if (
column &&
typeof column.text === 'string' &&
column.text.trim().length > 0
) {
if (column && typeof column.text === 'string' && column.text.trim().length > 0) {
isEmptyColumn = false;
break;
}
Expand Down Expand Up @@ -80,15 +76,15 @@ const createTable = (rows: RowData[]) => {
normalizeColumCount(rows);
normalizeColumnWidth(rows);

const th = rows.find(r => r.isHeader);
const th = rows.find((r) => r.isHeader);
if (th) {
const headerRow = createRow(th);
content.push(headerRow);
content.push(createBorder(th));
}

const tds = rows.filter(r => !r.isHeader);
tds.forEach(td => {
const tds = rows.filter((r) => !r.isHeader);
tds.forEach((td) => {
content.push(createRow(td));
});

Expand All @@ -101,7 +97,7 @@ const createBorder = (th: RowData) => {
isHeader: false,
};

th.columns.forEach(c => {
th.columns.forEach((c) => {
const borderCol: ColumnData = {
text: '',
width: c.width,
Expand All @@ -118,7 +114,7 @@ const createBorder = (th: RowData) => {
const createRow = (row: RowData) => {
const content: string[] = ['| '];

row.columns.forEach(c => {
row.columns.forEach((c) => {
content.push(c.text);
content.push(' | ');
});
Expand All @@ -129,13 +125,13 @@ const createRow = (row: RowData) => {
const normalizeColumCount = (rows: RowData[]) => {
let columnCount = 0;

rows.forEach(r => {
rows.forEach((r) => {
if (r.columns.length > columnCount) {
columnCount = r.columns.length;
}
});

rows.forEach(r => {
rows.forEach((r) => {
while (r.columns.length < columnCount) {
r.columns.push({
text: ``,
Expand All @@ -151,14 +147,14 @@ const normalizeColumnWidth = (rows: RowData[]) => {
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
let longestText = 0;

rows.forEach(r => {
rows.forEach((r) => {
const col = r.columns[columnIndex];
if (col.text.length > longestText) {
longestText = col.text.length;
}
});

rows.forEach(r => {
rows.forEach((r) => {
const col = r.columns[columnIndex];
col.width = longestText;
while (col.text.length < longestText) {
Expand Down
Loading

0 comments on commit e5bb5ce

Please sign in to comment.